diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29bb2d..fef41174fc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1 @@ +- Fixes issue with custom 404 pages not being returned in Next.js in the emulator (#8035). diff --git a/src/frameworks/utils.ts b/src/frameworks/utils.ts index 2bb8a9a0bd5..19e3414cbb9 100644 --- a/src/frameworks/utils.ts +++ b/src/frameworks/utils.ts @@ -208,7 +208,12 @@ export function simpleProxy(hostOrRequestHandler: string | RequestHandler) { originalRes.end(); }); } else { - const proxiedRes = proxyResponse(originalReq, originalRes, next); + const proxiedRes = proxyResponse(originalReq, originalRes, () => { + // This next function is called when the proxied response is a 404 + // In that case we want to let the handler to use the original response + void hostOrRequestHandler(originalReq, originalRes, next); + }); + await hostOrRequestHandler(originalReq, proxiedRes, next); } };