diff --git a/.changeset/grumpy-students-smell.md b/.changeset/grumpy-students-smell.md new file mode 100644 index 00000000..9372912b --- /dev/null +++ b/.changeset/grumpy-students-smell.md @@ -0,0 +1,5 @@ +--- +"open-next": patch +--- + +fix: prevent duplication of location header diff --git a/packages/open-next/src/adapters/routing/middleware.ts b/packages/open-next/src/adapters/routing/middleware.ts index 86f825af..85eb02b3 100644 --- a/packages/open-next/src/adapters/routing/middleware.ts +++ b/packages/open-next/src/adapters/routing/middleware.ts @@ -123,18 +123,16 @@ export async function handleMiddleware( // If the middleware returned a Redirect, we set the `Location` header with // the redirected url and end the response. if (res.statusCode >= 300 && res.statusCode < 400) { - const location = result.response.headers - .get("location") - ?.replace("http://localhost:3000", `https://${req.headers.host}`); + resHeaders.location = resHeaders.location?.replace( + "http://localhost:3000", + `https://${req.headers.host}`, + ); // res.setHeader("Location", location); return { body: "", type: internalEvent.type, statusCode: res.statusCode, - headers: { - ...resHeaders, - Location: location ?? "", - }, + headers: resHeaders, isBase64Encoded: false, }; }