BREAKING(http): switch params and info args in Handler for more conveniency

This commit is contained in:
Simon Lecoq 2024-10-05 16:31:45 +00:00 committed by GitHub
parent 065296ca5a
commit 4cd2e8c760
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 5 deletions

View File

@ -13,8 +13,8 @@
*/
export type Handler = (
request: Request,
params?: URLPatternResult,
info?: Deno.ServeHandlerInfo,
params?: URLPatternResult | null,
) => Response | Promise<Response>;
/**
@ -56,7 +56,7 @@ export interface Route {
* },
* {
* pattern: new URLPattern({ pathname: "/users/:id" }),
* handler: (_req, _info, params) => new Response(params?.pathname.groups.id),
* handler: (_req, params) => new Response(params?.pathname.groups.id),
* },
* {
* pattern: new URLPattern({ pathname: "/static/*" }),
@ -102,7 +102,7 @@ export function route(
? route.method.includes(request.method)
: request.method === (route.method ?? "GET"))
) {
return route.handler(request, info, match);
return route.handler(request, match, info);
}
}
return defaultHandler(request, info);

View File

@ -10,8 +10,7 @@ const routes: Route[] = [
},
{
pattern: new URLPattern({ pathname: "/users/:id" }),
handler: (_request, _info, params) =>
new Response(params?.pathname.groups.id),
handler: (_request, params) => new Response(params?.pathname.groups.id),
},
{
pattern: new URLPattern({ pathname: "/users/:id" }),