From 0d49698476a5eeefad49aa63fee3e3b9bf3c6c54 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 26 Jul 2023 11:40:50 +0200 Subject: [PATCH] switch back to rule cache --- src/router.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/router.ts b/src/router.ts index 46bd36eb..37312be2 100644 --- a/src/router.ts +++ b/src/router.ts @@ -49,7 +49,6 @@ export function createRouter(opts: CreateRouterOptions = {}): Router { const routes: Record = {}; let _matcher: RouteMatcher | undefined; - const _shadowedRoutes: Record = {}; const router: Router = {} as Router; @@ -109,9 +108,7 @@ export function createRouter(opts: CreateRouterOptions = {}): Router { ).toLowerCase() as RouterMethod; let handler: EventHandler | undefined = - matched.handlers[method] || - matched.handlers.all || - _shadowedRoutes[`${path}?${method}`]; + matched.handlers[method] || matched.handlers.all; // Fallback to search for shadowed routes if (!handler) { @@ -121,9 +118,14 @@ export function createRouter(opts: CreateRouterOptions = {}): Router { // Default order is less specific to most specific const _matches = _matcher.matchAll(path).reverse() as RouteNode[]; for (const _match of _matches) { - handler = _match.handlers[method] || _match.handlers.all; - if (handler) { - _shadowedRoutes[`${path}?${method}`] = handler; + if (_match.handlers[method]) { + handler = _match.handlers[method]; + matched.handlers[method] = matched.handlers[method] || handler; + break; + } + if (_match.handlers.all) { + handler = _match.handlers.all; + matched.handlers.all = matched.handlers.all || handler; break; } }