diff options
author | Alexis Hovorka <[email protected]> | 2024-02-21 16:17:24 -0700 |
---|---|---|
committer | Alexis Hovorka <[email protected]> | 2024-02-21 16:17:24 -0700 |
commit | caa495340aef5b765bed193da51cd4bf48a4d570 (patch) | |
tree | 3c12ea9841961d454bfba41ab1c32889537d5804 /app/lib | |
parent | 8f44593d55c82197854d9e29174fe66c4e50ebde (diff) |
[fix] Misc cleanup
Diffstat (limited to 'app/lib')
-rw-r--r-- | app/lib/router.js | 5 | ||||
-rw-r--r-- | app/lib/static.js | 4 |
2 files changed, 5 insertions, 4 deletions
diff --git a/app/lib/router.js b/app/lib/router.js index 186e6ad..7d30ccf 100644 --- a/app/lib/router.js +++ b/app/lib/router.js @@ -1,4 +1,4 @@ -import {parse as parseURL} from "node:url"; +import {URL} from "node:url"; const degroup = path => Object.assign(path, path.groups); export default class Router { @@ -7,7 +7,7 @@ export default class Router { } route(req, res) { - const pathname = parseURL(req.url).pathname; + const pathname = new URL(req.url, "file:").pathname; // TODO double-check return this.routes.some(route => { const isMatch = route.method === req.method && route.re.test(pathname); if (isMatch) route.cb(req, res, degroup(route.re.exec(pathname))); @@ -30,6 +30,7 @@ export default class Router { } jpost(re, cb, max) { + // TODO check req content-type? set accepts? this.gpost(re, (req, res, match, data) => { try { data = JSON.parse(data); diff --git a/app/lib/static.js b/app/lib/static.js index 26fc231..08c877f 100644 --- a/app/lib/static.js +++ b/app/lib/static.js @@ -1,5 +1,5 @@ import {normalize, extname} from "node:path"; -import {parse as parseURL} from "node:url"; +import {URL} from "node:url"; import fs from "node:fs"; const mimeTypes = { @@ -46,7 +46,7 @@ export default class Static { return; } - const pathname = parseURL(req.url).pathname; + const pathname = new URL(req.url, "file:").pathname; // TODO double-check const sane = normalize(pathname).replace(/^(\.\.\/)+/, ""); let path = `${this.root}${sane}`; //Path.join(__dirname, sane); |