diff options
author | EuAndreh <eu@euandre.org> | 2024-02-25 05:01:00 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-02-25 05:01:00 -0300 |
commit | 458bf0fc628d9bcf6a59a0efb898045266dab6ba (patch) | |
tree | bb538753668dad5abc7eec4a65bf4f233b34d93a /src/hero.mjs | |
parent | Normalize how modules import and name each other (diff) | |
download | papod-458bf0fc628d9bcf6a59a0efb898045266dab6ba.tar.gz papod-458bf0fc628d9bcf6a59a0efb898045266dab6ba.tar.xz |
Explicit import from "node:process"; move log() to hero.mjs
Diffstat (limited to 'src/hero.mjs')
-rw-r--r-- | src/hero.mjs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/hero.mjs b/src/hero.mjs index aa4a5a4..899e3fb 100644 --- a/src/hero.mjs +++ b/src/hero.mjs @@ -1,6 +1,7 @@ -import assert from "node:assert/strict"; -import crypto from "node:crypto"; -import http from "node:http"; +import assert from "node:assert/strict"; +import crypto from "node:crypto"; +import http from "node:http"; +import process from "node:process"; import * as u from "./utils.mjs"; @@ -121,7 +122,7 @@ export const handleRequest = async (table, method, url) => { if (!handler) { return { status: 404, - body: "Not Found", + body: "Not Found\n", }; } @@ -144,12 +145,14 @@ export const makeRequestListener = table => async (req, res) => { res.end(response.body); }; +export const log = o => console.error(JSON.stringify(o)); + export const interceptorsFn = ({ uuidFn, logger, } = { uuidFn: crypto.randomUUID, - logger: u.log, + logger: log, }) => ({ requestId: (req, next) => next({ ...req, id: uuidFn() }), logged: async (req, next) => { @@ -197,7 +200,7 @@ export const interceptorsFn = ({ }); return { status: 500, - body: "Internal Server Error", + body: "Internal Server Error\n", }; } }, |