Skip to content

Commit 939055f

Browse files
committed
fix(preview): Ensure the protocol in redirects from server actions
1 parent e16868f commit 939055f

File tree

1 file changed

+8
-0
lines changed
  • packages/cloudflare/src/cli/templates

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ 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+
if (url.hostname === "localhost") {
141+
process.env.__NEXT_PRIVATE_ORIGIN = url.origin;
142+
}
135143
}
136144

137145
/* eslint-disable no-var */

0 commit comments

Comments
 (0)