Skip to content

Commit 64a10a6

Browse files
authored
fix(preview): Ensure the protocol is correct in redirects from server actions during preview mode (#689)
1 parent e16868f commit 64a10a6

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

.changeset/hip-bags-argue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
fix: Ensure the protocol is correct for redirects in server actions during preview mode

packages/cloudflare/src/cli/templates/init.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ function populateProcessEnv(url: URL, env: CloudflareEnv) {
132132
port: url.port,
133133
},
134134
});
135+
136+
/* We need to set this environment variable to make redirects work properly in preview mode.
137+
* Next sets this in standalone mode during `startServer`. Without this the protocol would always be `https` here:
138+
* https://github.com/vercel/next.js/blob/6b1e48080e896e0d44a05fe009cb79d2d3f91774/packages/next/src/server/app-render/action-handler.ts#L307-L316
139+
*/
140+
process.env.__NEXT_PRIVATE_ORIGIN = url.origin;
135141
}
136142

137143
/* eslint-disable no-var */

0 commit comments

Comments
 (0)