Skip to content

Commit ed06cbd

Browse files
lowlighterkt3k
andauthored
BREAKING(http/unstable): switch params and info args in Handler in route() for more conveniency (#6094)
Co-authored-by: Yoshiya Hinosawa <[email protected]>
1 parent b1b8279 commit ed06cbd

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

http/mod.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,3 @@ export * from "./negotiation.ts";
104104
export * from "./server_sent_event_stream.ts";
105105
export * from "./user_agent.ts";
106106
export * from "./file_server.ts";
107-
// We keep this re-export as an exception for now as it's used in
108-
// `deno init --serve` output
109-
export * from "./unstable_route.ts";

http/unstable_route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
*/
1414
export type Handler = (
1515
request: Request,
16+
params?: URLPatternResult,
1617
info?: Deno.ServeHandlerInfo,
17-
params?: URLPatternResult | null,
1818
) => Response | Promise<Response>;
1919

2020
/**
@@ -56,7 +56,7 @@ export interface Route {
5656
* },
5757
* {
5858
* pattern: new URLPattern({ pathname: "/users/:id" }),
59-
* handler: (_req, _info, params) => new Response(params?.pathname.groups.id),
59+
* handler: (_req, params) => new Response(params?.pathname.groups.id),
6060
* },
6161
* {
6262
* pattern: new URLPattern({ pathname: "/static/*" }),
@@ -102,7 +102,7 @@ export function route(
102102
? route.method.includes(request.method)
103103
: request.method === (route.method ?? "GET"))
104104
) {
105-
return route.handler(request, info, match);
105+
return route.handler(request, match, info);
106106
}
107107
}
108108
return defaultHandler(request, info);

http/unstable_route_test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ const routes: Route[] = [
1010
},
1111
{
1212
pattern: new URLPattern({ pathname: "/users/:id" }),
13-
handler: (_request, _info, params) =>
14-
new Response(params?.pathname.groups.id),
13+
handler: (_request, params) => new Response(params?.pathname.groups.id),
1514
},
1615
{
1716
pattern: new URLPattern({ pathname: "/users/:id" }),

0 commit comments

Comments
 (0)