fix: fix the pass route not work with paths ending with "/"

This commit is contained in:
Dorian Niemiec 2025-01-01 21:10:09 +01:00
parent f7a6bc4f6a
commit db5c598a81

View file

@ -72,13 +72,14 @@ function svrouter() {
} else if (callback && typeof path !== "string") { } else if (callback && typeof path !== "string") {
throw new Error("The path must be a function"); throw new Error("The path must be a function");
} }
const realPath = callback ? path.replace(/\/+$/, "") : null;
routes.push({ routes.push({
method: null, method: null,
pathFunction: callback pathFunction: callback
? (checkedPath) => ? (checkedPath) =>
checkedPath == path || checkedPath == realPath ||
checkedPath.substring(0, path.length + 1) == path + "/" checkedPath.substring(0, realPath.length + 1) == realPath + "/"
? { ? {
path: checkedPath, path: checkedPath,
params: null params: null