From caa495340aef5b765bed193da51cd4bf48a4d570 Mon Sep 17 00:00:00 2001 From: Alexis Hovorka Date: Wed, 21 Feb 2024 16:17:24 -0700 Subject: [fix] Misc cleanup --- app/lib/router.js | 5 +++-- app/lib/static.js | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'app/lib') 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); -- cgit v1.2.3-70-g09d2