summaryrefslogtreecommitdiff
path: root/app/lib/router.js
diff options
context:
space:
mode:
authorAlexis Hovorka <[email protected]>2024-02-17 00:42:20 -0700
committerAlexis Hovorka <[email protected]>2024-02-17 00:42:20 -0700
commit8f44593d55c82197854d9e29174fe66c4e50ebde (patch)
treea43a6d763517d1304076897952b1111886303158 /app/lib/router.js
parentc5aa364e0e372d0e29063a27bd17811446db8b6a (diff)
[refactor] Switch to ES Modules
Diffstat (limited to 'app/lib/router.js')
-rw-r--r--app/lib/router.js10
1 files changed, 3 insertions, 7 deletions
diff --git a/app/lib/router.js b/app/lib/router.js
index fd24693..186e6ad 100644
--- a/app/lib/router.js
+++ b/app/lib/router.js
@@ -1,15 +1,13 @@
-"use strict"; // https://github.com/mixu/minimal
-
-const url = require("url");
+import {parse as parseURL} from "node:url";
const degroup = path => Object.assign(path, path.groups);
-class Router {
+export default class Router {
constructor() {
this.routes = [];
}
route(req, res) {
- const pathname = url.parse(req.url).pathname;
+ const pathname = parseURL(req.url).pathname;
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)));
@@ -49,5 +47,3 @@ class Router {
Router.prototype[method] = function(re, cb) {
this.routes.push({method: method.toUpperCase(), cb,
re: (re instanceof RegExp)? re : new RegExp(`^${re}$`)})});
-
-module.exports = Router;