@jsenv/server
Advanced tools
Comparing version 12.2.1 to 12.3.0
{ | ||
"name": "@jsenv/server", | ||
"version": "12.2.1", | ||
"version": "12.3.0", | ||
"description": "Write your Node.js server using pure functions", | ||
@@ -16,3 +16,3 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=16.12.0" | ||
"node": ">=16.13.0" | ||
}, | ||
@@ -42,3 +42,3 @@ "publishConfig": { | ||
"prettier": "prettier --write .", | ||
"certificate-authority-install": "node ./script/certificate/certificate_authority_install.mjs", | ||
"certificate-install": "node ./script/certificate/certificate_install.mjs", | ||
"playwright-install": "npx playwright install-deps && npx playwright install" | ||
@@ -49,3 +49,3 @@ }, | ||
"@jsenv/logger": "4.0.1", | ||
"@jsenv/url-meta": "6.0.1", | ||
"@jsenv/url-meta": "6.0.3", | ||
"node-fetch": "2.6.2", | ||
@@ -55,20 +55,20 @@ "path-to-regexp": "6.2.0" | ||
"devDependencies": { | ||
"@jsenv/assert": "2.4.0", | ||
"@jsenv/core": "24.5.0", | ||
"@jsenv/assert": "2.4.1", | ||
"@jsenv/core": "25.1.0", | ||
"@jsenv/eslint-config": "16.0.9", | ||
"@jsenv/filesystem": "2.6.0", | ||
"@jsenv/filesystem": "2.6.1", | ||
"@jsenv/github-release-package": "1.2.3", | ||
"@jsenv/https-local": "1.0.3", | ||
"@jsenv/importmap-eslint-resolver": "5.2.1", | ||
"@jsenv/importmap-node-module": "4.0.1", | ||
"@jsenv/importmap-eslint-resolver": "5.2.2", | ||
"@jsenv/importmap-node-module": "5.1.0", | ||
"@jsenv/package-publish": "1.6.2", | ||
"@jsenv/performance-impact": "2.2.1", | ||
"eslint": "8.4.1", | ||
"eslint-plugin-import": "2.25.3", | ||
"eslint": "8.7.0", | ||
"eslint-plugin-import": "2.25.4", | ||
"eventsource": "1.1.0", | ||
"fastify": "3.25.0", | ||
"fastify": "3.25.3", | ||
"fastify-static": "4.5.0", | ||
"playwright": "1.17.1", | ||
"playwright": "1.17.2", | ||
"prettier": "2.5.1" | ||
} | ||
} |
@@ -475,4 +475,4 @@ import http from "node:http" | ||
}) | ||
let { aborted, error, responseProperties } = responseFromShortcircuit | ||
? { responseProperties: responseFromShortcircuit } | ||
const result = responseFromShortcircuit | ||
? { returnValue: responseFromShortcircuit } | ||
: await generateResponseDescription({ | ||
@@ -537,61 +537,56 @@ requestToResponse, | ||
const { aborted } = result | ||
if (aborted) { | ||
return ABORTED_RESPONSE_PROPERTIES | ||
} | ||
// internal error, create 500 response | ||
if (error) { | ||
if ( | ||
// stopOnInternalError stops server only if requestToResponse generated | ||
// a non controlled error (internal error). | ||
// if requestToResponse gracefully produced a 500 response (it did not throw) | ||
// then we can assume we are still in control of what we are doing | ||
stopOnInternalError | ||
) { | ||
// il faudrais pouvoir stop que les autres response ? | ||
stop(STOP_REASON_INTERNAL_ERROR) | ||
} | ||
const propertiesFromError = await serverInternalErrorToResponse(error, { | ||
request, | ||
sendServerInternalErrorDetails, | ||
}) | ||
responseProperties = composeTwoResponses( | ||
{ | ||
status: 500, | ||
statusText: statusToStatusText(500), | ||
headers: { | ||
// ensure error are not cached | ||
"cache-control": "no-store", | ||
"content-type": "text/plain", | ||
const readResponseProperties = async () => { | ||
const { error } = result | ||
// internal error, create 500 response | ||
if (error) { | ||
if ( | ||
// stopOnInternalError stops server only if requestToResponse generated | ||
// a non controlled error (internal error). | ||
// if requestToResponse gracefully produced a 500 response (it did not throw) | ||
// then we can assume we are still in control of what we are doing | ||
stopOnInternalError | ||
) { | ||
// il faudrais pouvoir stop que les autres response ? | ||
stop(STOP_REASON_INTERNAL_ERROR) | ||
} | ||
const propertiesFromError = await serverInternalErrorToResponse( | ||
error, | ||
{ | ||
request, | ||
sendServerInternalErrorDetails, | ||
}, | ||
}, | ||
propertiesFromError, | ||
) | ||
addRequestLog(requestNode, { | ||
type: "error", | ||
value: createDetailedMessage( | ||
`internal error while handling request`, | ||
) | ||
addRequestLog(requestNode, { | ||
type: "error", | ||
value: createDetailedMessage( | ||
`internal error while handling request`, | ||
{ | ||
"error stack": error.stack, | ||
}, | ||
), | ||
}) | ||
return composeTwoResponses( | ||
{ | ||
"error stack": error.stack, | ||
status: 500, | ||
statusText: statusToStatusText(500), | ||
headers: { | ||
// ensure error are not cached | ||
"cache-control": "no-store", | ||
"content-type": "text/plain", | ||
}, | ||
}, | ||
), | ||
}) | ||
} else { | ||
const { | ||
status = 501, | ||
statusText = statusToStatusText(status), | ||
headers = {}, | ||
body, | ||
...rest | ||
} = responseProperties || {} | ||
responseProperties = { | ||
status, | ||
statusText, | ||
headers, | ||
body, | ||
...rest, | ||
propertiesFromError, | ||
) | ||
} | ||
const responseProperties = normalizeResponseProperties( | ||
result.returnValue, | ||
) | ||
return responseProperties | ||
} | ||
let responseProperties = await readResponseProperties() | ||
// call every plugin "onResponse" hook | ||
@@ -610,3 +605,2 @@ requestPlugins.forEach((requestPlugin) => { | ||
}) | ||
if ( | ||
@@ -622,3 +616,2 @@ request.method !== "HEAD" && | ||
} | ||
return responseProperties | ||
@@ -756,2 +749,34 @@ } | ||
const normalizeResponseProperties = (returnValue) => { | ||
if (returnValue && returnValue.constructor.name === "Response") { | ||
const responseHeaders = {} | ||
const headersToIgnore = ["connection"] | ||
returnValue.headers.forEach((value, name) => { | ||
if (!headersToIgnore.includes(name)) { | ||
responseHeaders[name] = value | ||
} | ||
}) | ||
return { | ||
status: returnValue.status, | ||
statusText: returnValue.statusText, | ||
headers: responseHeaders, | ||
body: returnValue.body, // node-fetch assumed | ||
} | ||
} | ||
const { | ||
status = 501, | ||
statusText = statusToStatusText(status), | ||
headers = {}, | ||
body, | ||
...rest | ||
} = returnValue || {} | ||
return { | ||
status, | ||
statusText, | ||
headers, | ||
body, | ||
...rest, | ||
} | ||
} | ||
const generateResponseDescription = async ({ | ||
@@ -767,3 +792,3 @@ requestToResponse, | ||
return { | ||
responseProperties: returnValue, | ||
returnValue, | ||
} | ||
@@ -770,0 +795,0 @@ } catch (error) { |
134058
4178
+ Added@jsenv/url-meta@6.0.3(transitive)
- Removed@jsenv/url-meta@6.0.1(transitive)
Updated@jsenv/url-meta@6.0.3