Skip to content

Commit

Permalink
switch back to rule cache
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jul 26, 2023
1 parent e660db4 commit 0d49698
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export function createRouter(opts: CreateRouterOptions = {}): Router {
const routes: Record<string, RouteNode> = {};

let _matcher: RouteMatcher | undefined;
const _shadowedRoutes: Record<string, EventHandler> = {};

const router: Router = {} as Router;

Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

Check warning on line 125 in src/router.ts

View check run for this annotation

Codecov / codecov/patch

src/router.ts#L122-L125

Added lines #L122 - L125 were not covered by tests
if (_match.handlers.all) {
handler = _match.handlers.all;
matched.handlers.all = matched.handlers.all || handler;
break;
}
}
Expand Down

0 comments on commit 0d49698

Please sign in to comment.