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:
Your Name 2026-08-02 22:28:19 -04:00
parent 14f9ec3160
commit d01f1411c5

View file

@ -795,10 +795,13 @@ app.all("*", async (req, res) => {
try { try {
let routeMatch = null; 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]) { for (let { matcher, id } of routes[verb]) {
let matchFromRoute = matcher(req_path); let matchFromRoute = matcher(req_path);
if (matchFromRoute) { if (matchFromRoute) {
routeMatch = { params: matchFromRoute.params, id: id }; routeMatch = { params: matchFromRoute.params, id: id };
break;
} }
} }