summaryrefslogtreecommitdiff
path: root/app/lib/router.js
diff options
context:
space:
mode:
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;