Update API routes function
This commit is contained in:
+13
-6
@@ -28,8 +28,8 @@ export default async function ({ req }) {
|
||||
const contentLength = req.headers.get("content-length");
|
||||
if (contentLength) {
|
||||
const size = parseInt(contentLength, 10);
|
||||
if ((config?.maxRequestBodyMB &&
|
||||
size > config.maxRequestBodyMB * MBInBytes) ||
|
||||
if ((config?.max_request_body_mb &&
|
||||
size > config.max_request_body_mb * MBInBytes) ||
|
||||
size > ServerDefaultRequestBodyLimitBytes) {
|
||||
return Response.json({
|
||||
success: false,
|
||||
@@ -42,11 +42,18 @@ export default async function ({ req }) {
|
||||
});
|
||||
}
|
||||
}
|
||||
const res = await module["default"]({
|
||||
const target_module = (module["default"] ||
|
||||
module["handler"]);
|
||||
const res = await target_module?.({
|
||||
...routeParams,
|
||||
});
|
||||
if (is_dev) {
|
||||
res.headers.set("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
if (res instanceof Response) {
|
||||
if (is_dev) {
|
||||
res.headers.set("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
return res;
|
||||
return Response.json(res, {
|
||||
...(res.bunext_api_route_res_options || undefined),
|
||||
});
|
||||
}
|
||||
|
||||
Vendored
+7
-5
@@ -121,11 +121,7 @@ export type APIResponseObject<T extends {
|
||||
redirect?: string;
|
||||
};
|
||||
export type BunextServerRouteConfig = {
|
||||
maxRequestBodyMB?: number;
|
||||
};
|
||||
export type PageDistGenParams = {
|
||||
pageName: string;
|
||||
page_file: string;
|
||||
max_request_body_mb?: number;
|
||||
};
|
||||
export type LivePageDistGenParams = {
|
||||
component?: FC;
|
||||
@@ -299,3 +295,9 @@ export type GrabTSXModuleBatchMap = {
|
||||
tsx: string;
|
||||
page_file_path: string;
|
||||
};
|
||||
export type BunextAPIRouteHandler<T extends BunextAPIRouteJSONRes = BunextAPIRouteJSONRes & {
|
||||
[k: string]: any;
|
||||
}> = (params: BunxRouteParams) => Promise<Response | T> | Response | T;
|
||||
export type BunextAPIRouteJSONRes = {
|
||||
bunext_api_route_res_options?: ResponseInit;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user