Skip to content

Commit

Permalink
transform request too
Browse files Browse the repository at this point in the history
  • Loading branch information
tylersayshi committed Dec 31, 2024
1 parent 1ae137d commit b7bed58
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions packages/waku/src/router/create-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,7 @@ export type CreateApi = <Path extends string>(params: {
path: Path;
mode: 'static' | 'dynamic';
method: Method;
handler: (req: {
body: ReadableStream | null;
headers: Readonly<Record<string, string>>;
method: string;
}) => Promise<Response>;
handler: (req: Request) => Promise<Response>;
}) => void;

type RootItem = {
Expand Down Expand Up @@ -197,20 +193,6 @@ const createNestedElements = (
);
};

const convertResponse = (
res: Response,
): {
body?: ReadableStream;
headers?: Record<string, string | string[]>;
status?: number;
} => {
return {
...(res.body ? { body: res.body } : {}),
headers: Object.fromEntries(res.headers.entries()),
status: res.status,
};
};

export const createPages = <
AllPages extends (AnyPage | ReturnType<CreateLayout>)[],
>(
Expand Down Expand Up @@ -642,7 +624,14 @@ export const createPages = <
}
const { handler } = apiPathMap.get(routePath)!;

return convertResponse(await handler(request));
const req = new Request(path, request);
const res = await handler(req);

return {
...(res.body ? { body: res.body } : {}),
headers: Object.fromEntries(res.headers.entries()),
status: res.status,
};
},
});

Expand Down

0 comments on commit b7bed58

Please sign in to comment.