@srfnstack/spliffy 0.9.4 → 1.0.1
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/package.json +2 -2
- package/src/nodeModuleHandler.mjs +31 -17
- package/src/server.mjs +2 -2
- package/src/serverConfig.mjs +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@srfnstack/spliffy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"author": "snowbldr",
|
|
5
5
|
"private": false,
|
|
6
6
|
"homepage": "https://github.com/narcolepticsnowman/spliffy",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"cookie": "^0.4.1",
|
|
34
34
|
"etag": "^1.8.1",
|
|
35
|
-
"uWebSockets.js": "uNetworking/uWebSockets.js#v20.
|
|
35
|
+
"uWebSockets.js": "uNetworking/uWebSockets.js#v20.10.0",
|
|
36
36
|
"uuid": "^8.3.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
@@ -7,10 +7,18 @@ import { getContentTypeByExtension } from './content.mjs'
|
|
|
7
7
|
const stripLeadingSlash = p => p.startsWith('/') ? p.substr(1) : p
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
This
|
|
10
|
+
This helper will add all the configured node_module files to the given routes.
|
|
11
11
|
The configured node moduleRoutes must be explicit files, no pattern matching is supported.
|
|
12
12
|
Generating the list of files using pattern matching yourself is highly discouraged.
|
|
13
13
|
It is much safer to explicitly list every file you wish to be served so you don't inadvertently serve additional files.
|
|
14
|
+
|
|
15
|
+
The default method is to read and serve directly from the node_modules directory without copying.
|
|
16
|
+
if method is set to "copy", files are copied from node_modules to their final location within the routes dir folder.
|
|
17
|
+
|
|
18
|
+
The primary benefit of using this in copy mode is that the files will be automatically updated when the package version
|
|
19
|
+
is updated, and it improves IDE integration by making the file really available after first run.
|
|
20
|
+
|
|
21
|
+
This could be destructive if not configured correctly, hence the default of read only
|
|
14
22
|
*/
|
|
15
23
|
export function getNodeModuleRoutes (config) {
|
|
16
24
|
const nodeModuleRoutes = config.nodeModuleRoutes
|
|
@@ -20,7 +28,7 @@ export function getNodeModuleRoutes (config) {
|
|
|
20
28
|
if (!fs.existsSync(nodeModulesDir)) {
|
|
21
29
|
throw new Error(`Unable to find node_modules dir at ${nodeModulesDir}`)
|
|
22
30
|
}
|
|
23
|
-
const prefix = stripLeadingSlash(nodeModuleRoutes.routePrefix || 'lib')
|
|
31
|
+
const prefix = stripLeadingSlash(nodeModuleRoutes.routePrefix || 'lib/ext')
|
|
24
32
|
if (!Array.isArray(nodeModuleRoutes.files)) {
|
|
25
33
|
nodeModuleRoutes.files = [nodeModuleRoutes.files]
|
|
26
34
|
}
|
|
@@ -37,21 +45,27 @@ export function getNodeModuleRoutes (config) {
|
|
|
37
45
|
}
|
|
38
46
|
|
|
39
47
|
if (fs.existsSync(filePath)) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
if (nodeModuleRoutes.method === 'copy') {
|
|
49
|
+
const dest = path.join(config.routeDir, urlPath)
|
|
50
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true })
|
|
51
|
+
fs.copyFileSync(filePath, dest)
|
|
52
|
+
} else {
|
|
53
|
+
const parts = urlPath.split('/')
|
|
54
|
+
const lastPart = parts.pop()
|
|
55
|
+
const mw = {}
|
|
56
|
+
mergeMiddleware(config.middleware, mw)
|
|
57
|
+
mergeMiddleware(nodeModuleRoutes.middleware || {}, mw)
|
|
58
|
+
routes.push({
|
|
59
|
+
pathParameters: [],
|
|
60
|
+
urlPath,
|
|
61
|
+
filePath,
|
|
62
|
+
handlers: createStaticHandler(
|
|
63
|
+
filePath, getContentTypeByExtension(lastPart, config.staticContentTypes),
|
|
64
|
+
config.cacheStatic, config.staticCacheControl
|
|
65
|
+
),
|
|
66
|
+
middleware: mw
|
|
67
|
+
})
|
|
68
|
+
}
|
|
55
69
|
} else {
|
|
56
70
|
console.warn(`The specified node_modules file: ${file} does not exist and will not be served.`)
|
|
57
71
|
}
|
package/src/server.mjs
CHANGED
|
@@ -68,7 +68,7 @@ const getHttpsApp = (key, cert) => {
|
|
|
68
68
|
export async function startServer (config) {
|
|
69
69
|
if (!state.initialized) {
|
|
70
70
|
state.initialized = true
|
|
71
|
-
const routes = [...(
|
|
71
|
+
const routes = [...getNodeModuleRoutes(config), ...(await findRoutes(config))]
|
|
72
72
|
let app, port
|
|
73
73
|
if (config.httpsKeyFile) {
|
|
74
74
|
app = getHttpsApp(config.secure)
|
|
@@ -101,7 +101,7 @@ export async function startServer (config) {
|
|
|
101
101
|
app[appMethods[method]](route.urlPath.substr(0, route.urlPath.length - 2), theHandler)
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
if (!route.handlers.OPTIONS) {
|
|
104
|
+
if (config.autoOptions && !route.handlers.OPTIONS) {
|
|
105
105
|
app.options(route.urlPath, optionsHandler(config, route.middleware, Object.keys(route.handlers).join(', ')))
|
|
106
106
|
}
|
|
107
107
|
}
|
package/src/serverConfig.mjs
CHANGED