@jsenv/server 12.2.0 → 12.2.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 +17 -20
- package/src/cors/plugin_cors.js +1 -3
- package/src/internal/memoize.js +24 -0
- package/src/startServer.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/server",
|
|
3
|
-
"version": "12.2.
|
|
3
|
+
"version": "12.2.1",
|
|
4
4
|
"description": "Write your Node.js server using pure functions",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -31,43 +31,40 @@
|
|
|
31
31
|
"/main.js"
|
|
32
32
|
],
|
|
33
33
|
"scripts": {
|
|
34
|
-
"importmap
|
|
35
|
-
"
|
|
34
|
+
"importmap": "node ./script/importmap/importmap.mjs",
|
|
35
|
+
"eslint": "node ./node_modules/eslint/bin/eslint.js . --ext=.js,.mjs",
|
|
36
|
+
"performance": "node --expose-gc ./script/performance/performance.mjs --log",
|
|
36
37
|
"test": "node ./script/test/test.mjs",
|
|
37
38
|
"test-with-coverage": "npm run test -- --coverage",
|
|
38
39
|
"generate-html-snapshots": "node ./test/internal_error/generate_html_snapshot_files.mjs",
|
|
39
|
-
"
|
|
40
|
-
"prettier-check": "prettier --check .",
|
|
41
|
-
"prettier-write": "prettier --write .",
|
|
40
|
+
"prettier": "prettier --write .",
|
|
42
41
|
"certificate-authority-install": "node ./script/certificate/certificate_authority_install.mjs",
|
|
43
|
-
"playwright-install": "npx playwright install-deps && npx playwright install"
|
|
44
|
-
"prepublishOnly": "node ./script/publish/remove_postinstall.mjs",
|
|
45
|
-
"postpublish": "node ./script/publish/restore_postinstall.mjs"
|
|
42
|
+
"playwright-install": "npx playwright install-deps && npx playwright install"
|
|
46
43
|
},
|
|
47
44
|
"dependencies": {
|
|
48
|
-
"@jsenv/abort": "4.1.
|
|
45
|
+
"@jsenv/abort": "4.1.2",
|
|
49
46
|
"@jsenv/logger": "4.0.1",
|
|
50
47
|
"@jsenv/url-meta": "6.0.1",
|
|
51
48
|
"node-fetch": "2.6.2",
|
|
52
49
|
"path-to-regexp": "6.2.0"
|
|
53
50
|
},
|
|
54
51
|
"devDependencies": {
|
|
55
|
-
"@jsenv/assert": "2.
|
|
56
|
-
"@jsenv/core": "
|
|
52
|
+
"@jsenv/assert": "2.4.0",
|
|
53
|
+
"@jsenv/core": "24.5.0",
|
|
57
54
|
"@jsenv/eslint-config": "16.0.9",
|
|
58
|
-
"@jsenv/filesystem": "2.
|
|
55
|
+
"@jsenv/filesystem": "2.6.0",
|
|
59
56
|
"@jsenv/github-release-package": "1.2.3",
|
|
60
57
|
"@jsenv/https-local": "1.0.3",
|
|
61
|
-
"@jsenv/importmap-eslint-resolver": "5.1
|
|
62
|
-
"@jsenv/importmap-node-module": "
|
|
58
|
+
"@jsenv/importmap-eslint-resolver": "5.2.1",
|
|
59
|
+
"@jsenv/importmap-node-module": "4.0.1",
|
|
63
60
|
"@jsenv/package-publish": "1.6.2",
|
|
64
61
|
"@jsenv/performance-impact": "2.2.1",
|
|
65
|
-
"eslint": "8.
|
|
62
|
+
"eslint": "8.4.1",
|
|
66
63
|
"eslint-plugin-import": "2.25.3",
|
|
67
64
|
"eventsource": "1.1.0",
|
|
68
|
-
"fastify": "3.
|
|
65
|
+
"fastify": "3.25.0",
|
|
69
66
|
"fastify-static": "4.5.0",
|
|
70
|
-
"playwright": "1.
|
|
71
|
-
"prettier": "2.
|
|
67
|
+
"playwright": "1.17.1",
|
|
68
|
+
"prettier": "2.5.1"
|
|
72
69
|
}
|
|
73
|
-
}
|
|
70
|
+
}
|
package/src/cors/plugin_cors.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { urlToOrigin } from "@jsenv/filesystem"
|
|
2
|
-
|
|
3
1
|
export const jsenvAccessControlAllowedHeaders = ["x-requested-with"]
|
|
4
2
|
|
|
5
3
|
export const jsenvAccessControlAllowedMethods = [
|
|
@@ -107,7 +105,7 @@ const generateAccessControlHeaders = ({
|
|
|
107
105
|
allowedOriginArray.push(headers.origin)
|
|
108
106
|
vary.push("origin")
|
|
109
107
|
} else if ("referer" in headers) {
|
|
110
|
-
allowedOriginArray.push(
|
|
108
|
+
allowedOriginArray.push(new URL(headers.referer).origin)
|
|
111
109
|
vary.push("referer")
|
|
112
110
|
} else {
|
|
113
111
|
allowedOriginArray.push("*")
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const memoize = (compute) => {
|
|
2
|
+
let memoized = false
|
|
3
|
+
let memoizedValue
|
|
4
|
+
|
|
5
|
+
const fnWithMemoization = (...args) => {
|
|
6
|
+
if (memoized) {
|
|
7
|
+
return memoizedValue
|
|
8
|
+
}
|
|
9
|
+
// if compute is recursive wait for it to be fully done before storing the value
|
|
10
|
+
// so set memoized boolean after the call
|
|
11
|
+
memoizedValue = compute(...args)
|
|
12
|
+
memoized = true
|
|
13
|
+
return memoizedValue
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
fnWithMemoization.forget = () => {
|
|
17
|
+
const value = memoizedValue
|
|
18
|
+
memoized = false
|
|
19
|
+
memoizedValue = undefined
|
|
20
|
+
return value
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return fnWithMemoization
|
|
24
|
+
}
|
package/src/startServer.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import http from "node:http"
|
|
2
2
|
import cluster from "node:cluster"
|
|
3
|
-
import { memoize } from "@jsenv/filesystem"
|
|
4
3
|
import { createDetailedMessage, createLogger } from "@jsenv/logger"
|
|
5
4
|
import {
|
|
6
5
|
Abort,
|
|
@@ -23,6 +22,7 @@ import { listen, stopListening } from "./internal/listen.js"
|
|
|
23
22
|
import { composeTwoResponses } from "./internal/response_composition.js"
|
|
24
23
|
import { listenRequest } from "./internal/listenRequest.js"
|
|
25
24
|
import { listenServerConnectionError } from "./internal/listenServerConnectionError.js"
|
|
25
|
+
import { memoize } from "./internal/memoize.js"
|
|
26
26
|
import { jsenvServerInternalErrorToResponse } from "./jsenvServerInternalErrorToResponse.js"
|
|
27
27
|
import {
|
|
28
28
|
STOP_REASON_INTERNAL_ERROR,
|