Skip to content

Commit 6af9f88

Browse files
committed
fix(converters): Ensure x-forwarded-proto is set to http when running locally
1 parent ab492ca commit 6af9f88

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

packages/open-next/src/overrides/converters/edge.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ const converter: Converter<InternalEvent, InternalResult | MiddlewareResult> = {
3535
),
3636
);
3737

38+
// This is to make libraries (i.e next-auth) that rely on this header to work out of the box in `opennextjs-cloudflare preview`.
39+
if (url.protocol.slice(0, -1) === "http" && url.hostname === "localhost") {
40+
headers["x-forwarded-proto"] = "http";
41+
}
42+
3843
return {
3944
type: "core",
4045
method,

packages/open-next/src/overrides/converters/node.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ const converter: Converter = {
3030
`${req.protocol ? req.protocol : "http"}://${extractHostFromHeaders(headers)}${req.url}`,
3131
);
3232
const query = getQueryFromSearchParams(url.searchParams);
33+
34+
if (req.protocol === "http" && url.hostname === "localhost") {
35+
// This is used internally by Next.js during redirects in server actions. We need to set it to the origin of the request.
36+
process.env.__NEXT_PRIVATE_ORIGIN = url.origin;
37+
// This is to make `next-auth` and other libraries that rely on this header to work locally out of the box.
38+
headers["x-forwarded-proto"] = req.protocol;
39+
}
40+
3341
return {
3442
type: "core",
3543
method: req.method ?? "GET",

0 commit comments

Comments
 (0)