fixing
This commit is contained in:
parent
99e5baeefb
commit
09a819dcf1
|
|
@ -70,7 +70,15 @@ export const useServerRouter = <T extends ReturnType<typeof newServerRouter>>(
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
async handle(arg: ServerContext | SessionContext<any>) {
|
async handle(
|
||||||
|
arg: ServerContext | SessionContext<any>,
|
||||||
|
opt?: {
|
||||||
|
rewrite?: (arg: {
|
||||||
|
body: Bun.BodyInit;
|
||||||
|
headers?: Record<string, string>;
|
||||||
|
}) => Bun.BodyInit;
|
||||||
|
}
|
||||||
|
) {
|
||||||
const { url, req, handle } = arg;
|
const { url, req, handle } = arg;
|
||||||
const found = findRoute(rou, undefined, url.pathname);
|
const found = findRoute(rou, undefined, url.pathname);
|
||||||
if (found) {
|
if (found) {
|
||||||
|
|
@ -101,7 +109,7 @@ export const useServerRouter = <T extends ReturnType<typeof newServerRouter>>(
|
||||||
|
|
||||||
return new Response(JSON.stringify(result));
|
return new Response(JSON.stringify(result));
|
||||||
}
|
}
|
||||||
return handle(req);
|
return handle(req, opt);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,10 @@ export type SessionServerHandler = {
|
||||||
handle: (
|
handle: (
|
||||||
arg: ServerContext,
|
arg: ServerContext,
|
||||||
opt?: {
|
opt?: {
|
||||||
rewrite?: (arg: { body: Bun.BodyInit; headers: Headers }) => Bun.BodyInit;
|
rewrite?: (arg: {
|
||||||
|
body: Bun.BodyInit;
|
||||||
|
headers?: Record<string, string>;
|
||||||
|
}) => Bun.BodyInit;
|
||||||
}
|
}
|
||||||
) => Promise<Response>;
|
) => Promise<Response>;
|
||||||
};
|
};
|
||||||
|
|
@ -39,12 +42,12 @@ export const initSessionServer = <T>(
|
||||||
};
|
};
|
||||||
|
|
||||||
if (url.pathname.startsWith("/_session/")) {
|
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 (res) return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg.router) {
|
if (arg.router) {
|
||||||
const res = await arg.router.handle(route_arg);
|
const res = await arg.router.handle(route_arg, opt);
|
||||||
if (res) return res;
|
if (res) return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ export type ServerContext = {
|
||||||
opt?: {
|
opt?: {
|
||||||
rewrite?: (arg: {
|
rewrite?: (arg: {
|
||||||
body: Bun.BodyInit;
|
body: Bun.BodyInit;
|
||||||
headers: Response["headers"];
|
headers?: Record<string, string>;
|
||||||
}) => Bun.BodyInit;
|
}) => Bun.BodyInit;
|
||||||
}
|
}
|
||||||
) => Promise<Response>;
|
) => Promise<Response>;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue