diff --git a/server/server-route.ts b/server/server-route.ts index 2a8ef7b..2723b95 100755 --- a/server/server-route.ts +++ b/server/server-route.ts @@ -70,7 +70,15 @@ export const useServerRouter = >( } return { - async handle(arg: ServerContext | SessionContext) { + async handle( + arg: ServerContext | SessionContext, + opt?: { + rewrite?: (arg: { + body: Bun.BodyInit; + headers?: Record; + }) => Bun.BodyInit; + } + ) { const { url, req, handle } = arg; const found = findRoute(rou, undefined, url.pathname); if (found) { @@ -101,7 +109,7 @@ export const useServerRouter = >( return new Response(JSON.stringify(result)); } - return handle(req); + return handle(req, opt); }, }; }; diff --git a/session/server-session.ts b/session/server-session.ts index 5f036b4..e4181da 100755 --- a/session/server-session.ts +++ b/session/server-session.ts @@ -9,7 +9,10 @@ export type SessionServerHandler = { handle: ( arg: ServerContext, opt?: { - rewrite?: (arg: { body: Bun.BodyInit; headers: Headers }) => Bun.BodyInit; + rewrite?: (arg: { + body: Bun.BodyInit; + headers?: Record; + }) => Bun.BodyInit; } ) => Promise; }; @@ -39,12 +42,12 @@ export const initSessionServer = ( }; if (url.pathname.startsWith("/_session/")) { - const res = await session_router.handle(route_arg); + const res = await session_router.handle(route_arg, opt); if (res) return res; } if (arg.router) { - const res = await arg.router.handle(route_arg); + const res = await arg.router.handle(route_arg, opt); if (res) return res; } diff --git a/session/type.ts b/session/type.ts index bca46f1..e4614d3 100755 --- a/session/type.ts +++ b/session/type.ts @@ -76,7 +76,7 @@ export type ServerContext = { opt?: { rewrite?: (arg: { body: Bun.BodyInit; - headers: Response["headers"]; + headers?: Record; }) => Bun.BodyInit; } ) => Promise;