@jsenv/server 12.5.8 → 12.5.9
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/server",
|
|
3
|
-
"version": "12.5.
|
|
3
|
+
"version": "12.5.9",
|
|
4
4
|
"description": "Write your Node.js server using pure functions",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -16,8 +16,7 @@
|
|
|
16
16
|
"node": ">=16.13.0"
|
|
17
17
|
},
|
|
18
18
|
"publishConfig": {
|
|
19
|
-
"access": "public"
|
|
20
|
-
"registry": "https://registry.npmjs.org"
|
|
19
|
+
"access": "public"
|
|
21
20
|
},
|
|
22
21
|
"type": "module",
|
|
23
22
|
"exports": {
|
|
@@ -68,4 +67,4 @@
|
|
|
68
67
|
"playwright": "1.18.1",
|
|
69
68
|
"prettier": "2.5.1"
|
|
70
69
|
}
|
|
71
|
-
}
|
|
70
|
+
}
|
|
@@ -11,22 +11,21 @@ const cyan = "\x1b[36m"
|
|
|
11
11
|
|
|
12
12
|
export const colorizeResponseStatus = (status) => {
|
|
13
13
|
const statusType = statusToType(status)
|
|
14
|
-
|
|
15
14
|
if (statusType === "information") return `${cyan}${status}${close}`
|
|
16
15
|
if (statusType === "success") return `${green}${status}${close}`
|
|
17
16
|
if (statusType === "redirection") return `${magenta}${status}${close}`
|
|
18
|
-
if (statusType === "
|
|
19
|
-
if (statusType === "
|
|
17
|
+
if (statusType === "client_error") return `${yellow}${status}${close}`
|
|
18
|
+
if (statusType === "server_error") return `${red}${status}${close}`
|
|
20
19
|
return status
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
|
|
24
|
-
const statusToType = (status) => {
|
|
23
|
+
export const statusToType = (status) => {
|
|
25
24
|
if (statusIsInformation(status)) return "information"
|
|
26
25
|
if (statusIsSuccess(status)) return "success"
|
|
27
26
|
if (statusIsRedirection(status)) return "redirection"
|
|
28
|
-
if (statusIsClientError(status)) return "
|
|
29
|
-
if (statusIsServerError(status)) return "
|
|
27
|
+
if (statusIsClientError(status)) return "client_error"
|
|
28
|
+
if (statusIsServerError(status)) return "server_error"
|
|
30
29
|
return "unknown"
|
|
31
30
|
}
|
|
32
31
|
|
package/src/startServer.js
CHANGED
|
@@ -16,7 +16,10 @@ import {
|
|
|
16
16
|
applyRedirectionToRequest,
|
|
17
17
|
} from "./internal/request_factory.js"
|
|
18
18
|
import { populateNodeResponse } from "./internal/populateNodeResponse.js"
|
|
19
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
statusToType,
|
|
21
|
+
colorizeResponseStatus,
|
|
22
|
+
} from "./internal/colorizeResponseStatus.js"
|
|
20
23
|
import { getServerOrigins } from "./internal/getServerOrigins.js"
|
|
21
24
|
import { listen, stopListening } from "./internal/listen.js"
|
|
22
25
|
import { composeTwoResponses } from "./internal/response_composition.js"
|
|
@@ -676,8 +679,15 @@ export const startServer = async ({
|
|
|
676
679
|
onRequestHandled(requestNode)
|
|
677
680
|
},
|
|
678
681
|
onHeadersSent: ({ status, statusText }) => {
|
|
682
|
+
const statusType = statusToType(status)
|
|
679
683
|
addRequestLog(requestNode, {
|
|
680
|
-
type:
|
|
684
|
+
type: {
|
|
685
|
+
information: "info",
|
|
686
|
+
success: "info",
|
|
687
|
+
redirection: "info",
|
|
688
|
+
client_error: "warn",
|
|
689
|
+
server_error: "error",
|
|
690
|
+
}[statusType],
|
|
681
691
|
value: `${colorizeResponseStatus(status)} ${
|
|
682
692
|
responseProperties.statusMessage || statusText
|
|
683
693
|
}`,
|