Fix memory leak in dev server
This commit is contained in:
@@ -26,7 +26,12 @@ export default async function bunextRequestHandler({
|
||||
server,
|
||||
}: Params): Promise<Response> {
|
||||
const is_dev = isDevelopment();
|
||||
let req = initial_req.clone();
|
||||
const middleware = global.BUNEXT_CONSTANTS.config?.middleware;
|
||||
|
||||
// Middleware may consume `initial_req`'s body, so it gets its own copy.
|
||||
// Cloning tees the body stream and buffers whatever one side doesn't
|
||||
// read, so only pay for it when middleware is configured.
|
||||
let req = middleware ? initial_req.clone() : initial_req;
|
||||
|
||||
try {
|
||||
let url = new URL(req.url);
|
||||
@@ -40,12 +45,11 @@ export default async function bunextRequestHandler({
|
||||
|
||||
let response: Response | undefined = undefined;
|
||||
|
||||
if (global.BUNEXT_CONSTANTS.config?.middleware) {
|
||||
const middleware_res =
|
||||
await global.BUNEXT_CONSTANTS.config.middleware({
|
||||
req: initial_req,
|
||||
url,
|
||||
});
|
||||
if (middleware) {
|
||||
const middleware_res = await middleware({
|
||||
req: initial_req,
|
||||
url,
|
||||
});
|
||||
|
||||
if (middleware_res instanceof Response) {
|
||||
return middleware_res;
|
||||
|
||||
Reference in New Issue
Block a user