Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use correct protocol and hostname for internal redirections in Server Actions #63389

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/next/src/server/app-render/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,13 @@ async function createRedirectRenderResult(
const proto =
staticGenerationStore.incrementalCache?.requestProtocol || 'https'

// For standalone or the serverful mode, use the internal hostname directly
// other than the headers from the request.
const host = process.env.__NEXT_PRIVATE_HOST || originalHost.value
// For standalone or the serverful mode, use the internal origin directly
// other than the host headers from the request.
const origin =
process.env.__NEXT_PRIVATE_ORIGIN || `${proto}://${originalHost.value}`

const fetchUrl = new URL(
`${proto}://${host}${basePath}${parsedRedirectUrl.pathname}${parsedRedirectUrl.search}`
`${origin}${basePath}${parsedRedirectUrl.pathname}${parsedRedirectUrl.search}`
)

if (staticGenerationStore.revalidatedTags) {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/lib/start-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export async function startServer(

// expose the main port to render workers
process.env.PORT = port + ''
process.env.__NEXT_PRIVATE_HOST = `${actualHostname}:${port}`
process.env.__NEXT_PRIVATE_ORIGIN = appUrl

// Only load env and config in dev to for logging purposes
let envInfo: string[] | undefined
Expand Down