fix: make the most recently saved route win on path conflicts
The matcher loop kept the last match instead of the first. Since routes[verb] is ordered by updated_at DESC, that meant the OLDEST route won when two routes matched the same path. Break on first match so the most recently saved route wins. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
14f9ec3160
commit
d01f1411c5
1 changed files with 3 additions and 0 deletions
3
index.js
3
index.js
|
|
@ -795,10 +795,13 @@ app.all("*", async (req, res) => {
|
|||
try {
|
||||
let routeMatch = null;
|
||||
|
||||
// routes[verb] is ordered most-recently-updated first (getAllRoutes sorts
|
||||
// by updated_at DESC), so the first match is the most recently saved route.
|
||||
for (let { matcher, id } of routes[verb]) {
|
||||
let matchFromRoute = matcher(req_path);
|
||||
if (matchFromRoute) {
|
||||
routeMatch = { params: matchFromRoute.params, id: id };
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue