Skip to content

Commit 3235392

Browse files
r34sonconico974
andauthored
fix: prevent duplication of location header (#369)
* fix: prevent duplication of location header * changeset * fix linting --------- Co-authored-by: conico974 <nicodorseuil@yahoo.fr>
1 parent af2d3ce commit 3235392

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

.changeset/grumpy-students-smell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"open-next": patch
3+
---
4+
5+
fix: prevent duplication of location header

packages/open-next/src/adapters/routing/middleware.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,16 @@ export async function handleMiddleware(
123123
// If the middleware returned a Redirect, we set the `Location` header with
124124
// the redirected url and end the response.
125125
if (res.statusCode >= 300 && res.statusCode < 400) {
126-
const location = result.response.headers
127-
.get("location")
128-
?.replace("http://localhost:3000", `https://${req.headers.host}`);
126+
resHeaders.location = resHeaders.location?.replace(
127+
"http://localhost:3000",
128+
`https://${req.headers.host}`,
129+
);
129130
// res.setHeader("Location", location);
130131
return {
131132
body: "",
132133
type: internalEvent.type,
133134
statusCode: res.statusCode,
134-
headers: {
135-
...resHeaders,
136-
Location: location ?? "",
137-
},
135+
headers: resHeaders,
138136
isBase64Encoded: false,
139137
};
140138
}

0 commit comments

Comments
 (0)