Unverified Commit 8f7a6ca7 authored by Shu Ding's avatar Shu Ding Committed by GitHub

Improve redirection handling (#62561)

Currently to redirect to another RSC route of the same app, we initiate
another request to that route. This PR changes that request to directly
use the internal hostname of the current server handler, rather than
relying on other headers.

Closes NEXT-2614
parent 18200a84
......@@ -179,9 +179,13 @@ async function createRedirectRenderResult(
const forwardedHeaders = getForwardedHeaders(req, res)
forwardedHeaders.set(RSC_HEADER, '1')
const host = originalHost.value
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
const fetchUrl = new URL(
`${proto}://${host}${basePath}${parsedRedirectUrl.pathname}`
)
......
......@@ -246,6 +246,7 @@ export async function startServer(
// expose the main port to render workers
process.env.PORT = port + ''
process.env.__NEXT_PRIVATE_HOST = `${actualHostname}:${port}`
// Only load env and config in dev to for logging purposes
let envInfo: string[] | undefined
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment