Skip to content

Commit 8f7a6ca

Browse files
authored
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 18200a8 commit 8f7a6ca

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,13 @@ async function createRedirectRenderResult(
179179
const forwardedHeaders = getForwardedHeaders(req, res)
180180
forwardedHeaders.set(RSC_HEADER, '1')
181181

182-
const host = originalHost.value
183182
const proto =
184183
staticGenerationStore.incrementalCache?.requestProtocol || 'https'
184+
185+
// For standalone or the serverful mode, use the internal hostname directly
186+
// other than the headers from the request.
187+
const host = process.env.__NEXT_PRIVATE_HOST || originalHost.value
188+
185189
const fetchUrl = new URL(
186190
`${proto}://${host}${basePath}${parsedRedirectUrl.pathname}`
187191
)

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

Lines changed: 1 addition & 0 deletions
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)