MCPcopy Create free account
hub / github.com/denoland/std / routeLinear

Function routeLinear

http/unstable_route.ts:99–112  ·  view source on GitHub ↗
(
  routes: Route[],
  defaultHandler: RequestHandler,
)

Source from the content-addressed store, hash-verified

97 * @returns Request handler
98 */
99export function routeLinear(
100 routes: Route[],
101 defaultHandler: RequestHandler,
102): RequestHandler {
103 // TODO(iuioiua): Use `URLPatternList` once available (https://github.com/whatwg/urlpattern/pull/166)
104 return (request: Request, info?: Deno.ServeHandlerInfo) => {
105 for (const route of routes) {
106 if (!methodMatches(route.method, request.method)) continue;
107 const match = route.pattern.exec(request.url);
108 if (match) return route.handler(request, match, info);
109 }
110 return defaultHandler(request, info);
111 };
112}
113
114// ---------------------------------------------------------------------------
115// Radix tree router

Callers 2

routeRadixFunction · 0.85

Calls 2

methodMatchesFunction · 0.85
defaultHandlerFunction · 0.70

Tested by

no test coverage detected