Skip to content

Commit 9bbd082

Browse files
committed
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
1 parent 22ba4cd commit 9bbd082

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

packages/next/src/server/app-render/action-handler.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ async function createRedirectRenderResult(
157157
const forwardedHeaders = getForwardedHeaders(req, res)
158158
forwardedHeaders.set(RSC_HEADER, '1')
159159

160-
const host = req.headers['host']
160+
// For standalone or the serverful mode, use the internal hostname directly
161+
// other than the headers from the request.
162+
const host = process.env.__NEXT_PRIVATE_HOST || req.headers['host']
161163
const proto =
162164
staticGenerationStore.incrementalCache?.requestProtocol || 'https'
163165
const fetchUrl = new URL(`${proto}://${host}${basePath}${redirectUrl}`)

packages/next/src/server/lib/start-server.ts

+1
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ export async function startServer(
246246

247247
// expose the main port to render workers
248248
process.env.PORT = port + ''
249+
process.env.__NEXT_PRIVATE_HOST = `${actualHostname}:${port}`
249250

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

0 commit comments

Comments
 (0)