This commit is contained in:
Flummi 2025-03-17 09:04:11 +01:00
parent 566a1b671c
commit b694b14065
3 changed files with 7 additions and 7 deletions

2
dist/index.js vendored
View File

@ -124,7 +124,7 @@ export default class Flummpress {
res.reply({ code, type: "text/html", body });
};
res.redirect = (target, code = 302) => {
res.writeHead(code, { Location: target });
res.writeHead(code, { Location: encodeURI(target) });
res.end();
};
return res;

10
dist/router.js vendored
View File

@ -13,7 +13,6 @@ import Tpl from "./template.js";
export default class Router {
constructor() {
this.routes = [];
this.routes;
this.mimes = new Map();
}
importRoutesFromPath(p_1) {
@ -71,6 +70,7 @@ export default class Router {
}
use(obj) {
if (obj instanceof Router) {
this.routes = Object.assign(Object.assign({}, this.routes), obj.routes);
this.sortRoutes();
}
if (obj instanceof Tpl) {
@ -102,12 +102,12 @@ export default class Router {
return this;
}
registerRoute(path, method, handler) {
const existingRoute = this.routes.find(route => typeof route.path === "string"
const route = this.routes.find(route => typeof route.path === "string"
? route.path === path
: route.path instanceof RegExp && path instanceof RegExp && route.path.toString() === path.toString());
if (existingRoute) {
existingRoute.methods[method] = [
...(existingRoute.methods[method] || []),
if (route) {
route.methods[method] = [
...(route.methods[method] || []),
...handler
];
}

View File

@ -198,7 +198,7 @@ export default class Flummpress {
};
res.redirect = (target, code = 302) => {
res.writeHead(code, { Location: target });
res.writeHead(code, { Location: encodeURI(target) });
res.end();
};