|
1 | 1 | import { type ZodType } from "zod";
|
2 | 2 | import { parseRequestBody, resolveRequestBody } from "./core/body";
|
3 | 3 | import { resolveParams } from "./core/params";
|
| 4 | +import parsePathParams from "./core/path-params"; |
4 | 5 | import { addBadRequest, bundleResponses } from "./core/responses";
|
5 | 6 | import parseSearchParams from "./core/search-params";
|
6 | 7 | import type { HttpMethod } from "./types/http";
|
@@ -39,13 +40,10 @@ export default function createRoute<M extends HttpMethod, PP, QP, RB>(input: Rou
|
39 | 40 | const handler: RouteMethodHandler<PP> = async (request, props) => {
|
40 | 41 | try {
|
41 | 42 | const { searchParams } = new URL(request.url);
|
42 |
| - const queryParams = parseSearchParams(searchParams, input.queryParams); |
43 |
| - const body = await parseRequestBody(request, input.method, input.requestBody ?? undefined); |
44 |
| - return await input.action({ |
45 |
| - pathParams: (props.params ?? null) as PP, |
46 |
| - queryParams: queryParams as QP, |
47 |
| - body: body as RB, |
48 |
| - }); |
| 43 | + const pathParams = parsePathParams(props.params, input.pathParams) as PP; |
| 44 | + const queryParams = parseSearchParams(searchParams, input.queryParams) as QP; |
| 45 | + const body = await parseRequestBody(request, input.method, input.requestBody ?? undefined) as RB; |
| 46 | + return await input.action({ pathParams, queryParams, body }); |
49 | 47 | } catch (error) {
|
50 | 48 | if (error instanceof Error && error.constructor.name === "ZodError") {
|
51 | 49 | return new Response(null, { status: 400 });
|
|
0 commit comments