Unverified Commit 9bbd0821 authored by Shu Ding's avatar Shu Ding

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 22ba4cde
......@@ -157,7 +157,9 @@ async function createRedirectRenderResult(
const forwardedHeaders = getForwardedHeaders(req, res)
forwardedHeaders.set(RSC_HEADER, '1')
const host = req.headers['host']
// 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 || req.headers['host']
const proto =
staticGenerationStore.incrementalCache?.requestProtocol || 'https'
const fetchUrl = new URL(`${proto}://${host}${basePath}${redirectUrl}`)
......
......@@ -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