From 60f3cd727a1a7b7680ab26fe076f0277b58fdaa5 Mon Sep 17 00:00:00 2001 From: Chalo Salvador Date: Fri, 31 Jan 2025 10:32:02 +0100 Subject: [PATCH] Handle 404 status code in the proxyResponse. (#8119) * Handle 404 status code in the proxyResponse. * Changelog --------- Co-authored-by: Leonardo Ortiz --- CHANGELOG.md | 1 + src/frameworks/utils.ts | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) 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); } };