wiki-server 0.26.0-rc.8 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/page.js +26 -4
- package/lib/random_id.js +0 -1
- package/lib/server.js +8 -3
- package/package.json +1 -1
package/lib/page.js
CHANGED
|
@@ -22,16 +22,38 @@
|
|
|
22
22
|
|
|
23
23
|
import fs from 'node:fs'
|
|
24
24
|
import path from 'node:path'
|
|
25
|
-
import
|
|
25
|
+
import url from 'node:url'
|
|
26
26
|
import events from 'node:events'
|
|
27
27
|
|
|
28
28
|
import { createRequire } from 'node:module'
|
|
29
29
|
const require = createRequire(import.meta.url)
|
|
30
30
|
|
|
31
31
|
// Use dynamic import to load package.json from the main application's working directory
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
const wikiPackageImport = async () => {
|
|
33
|
+
let done = false
|
|
34
|
+
return new Promise(resolve => {
|
|
35
|
+
import('wiki/package.json', { with: { type: 'json' } })
|
|
36
|
+
.then(imported => {
|
|
37
|
+
done = true
|
|
38
|
+
resolve(imported.default)
|
|
39
|
+
})
|
|
40
|
+
.catch(e => {
|
|
41
|
+
return e
|
|
42
|
+
})
|
|
43
|
+
.then(async () => {
|
|
44
|
+
if (done) return
|
|
45
|
+
const packageJsonPath = path.join(process.cwd(), 'package.json')
|
|
46
|
+
const packageJsonUrl = url.pathToFileURL(packageJsonPath).href
|
|
47
|
+
import(packageJsonUrl, { with: { type: 'json' } })
|
|
48
|
+
.then(imported => {
|
|
49
|
+
resolve(imported.default)
|
|
50
|
+
})
|
|
51
|
+
.catch(e => console.error('problems importing package', e))
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const packageJson = await wikiPackageImport()
|
|
35
57
|
|
|
36
58
|
// import random_id from './random_id.cjs'; // Uncomment if needed
|
|
37
59
|
import synopsis from 'wiki-client/lib/synopsis.js' // Add correct extension if necessary
|
package/lib/random_id.js
CHANGED
package/lib/server.js
CHANGED
|
@@ -61,15 +61,18 @@ const require = createRequire(import.meta.url)
|
|
|
61
61
|
// Use import to load package.json from the main application's working directory
|
|
62
62
|
//const { default: packageJson } = await import('wiki/package.json', { with: { type: 'json' } })
|
|
63
63
|
const wikiPackageImport = async () => {
|
|
64
|
+
let done = false
|
|
64
65
|
return new Promise(resolve => {
|
|
65
66
|
import('wiki/package.json', { with: { type: 'json' } })
|
|
66
67
|
.then(imported => {
|
|
68
|
+
done = true
|
|
67
69
|
resolve(imported.default)
|
|
68
70
|
})
|
|
69
71
|
.catch(e => {
|
|
70
72
|
return e
|
|
71
73
|
})
|
|
72
74
|
.then(async () => {
|
|
75
|
+
if (done) return
|
|
73
76
|
const packageJsonPath = path.join(process.cwd(), 'package.json')
|
|
74
77
|
const packageJsonUrl = url.pathToFileURL(packageJsonPath).href
|
|
75
78
|
import(packageJsonUrl, { with: { type: 'json' } })
|
|
@@ -132,6 +135,8 @@ export default async argv => {
|
|
|
132
135
|
|
|
133
136
|
app.startOpts = argv
|
|
134
137
|
|
|
138
|
+
const wikiName = new URL(argv.url).hostname
|
|
139
|
+
|
|
135
140
|
const log = (...stuff) => {
|
|
136
141
|
if (argv.debug) console.log(stuff)
|
|
137
142
|
}
|
|
@@ -252,7 +257,7 @@ export default async argv => {
|
|
|
252
257
|
// use logger, at least in development, probably needs a param to configure (or turn off).
|
|
253
258
|
// use stream to direct to somewhere other than stdout.
|
|
254
259
|
logger.token('vhost', (req, res) => {
|
|
255
|
-
return colorString(
|
|
260
|
+
return colorString(wikiName)
|
|
256
261
|
})
|
|
257
262
|
app.use(logger(':vhost :method :url :status :res[content-length] - :response-time ms'))
|
|
258
263
|
app.use(cookieParser())
|
|
@@ -492,7 +497,7 @@ export default async argv => {
|
|
|
492
497
|
if (!err) {
|
|
493
498
|
res.sendFile(favLoc, { dotfiles: 'allow' })
|
|
494
499
|
} else {
|
|
495
|
-
res.sendFile(defaultFavLoc)
|
|
500
|
+
res.sendFile(defaultFavLoc, { dotfiles: 'allow' })
|
|
496
501
|
}
|
|
497
502
|
})
|
|
498
503
|
})
|
|
@@ -724,7 +729,7 @@ export default async argv => {
|
|
|
724
729
|
return new Promise(resolve => {
|
|
725
730
|
try {
|
|
726
731
|
// Use import to load package.json from the main application's working directory
|
|
727
|
-
import(
|
|
732
|
+
import(`${packageName}/package.json`, { with: { type: 'json' } }).then(({ default: packageJson }) => {
|
|
728
733
|
resolve({ [packageName]: packageJson.version })
|
|
729
734
|
})
|
|
730
735
|
} catch (error) {
|