Skip to content

Commit

Permalink
Improve redirection handling (#62561)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
shuding authored Feb 27, 2024
1 parent 18200a8 commit 8f7a6ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/next/src/server/app-render/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
)
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/server/lib/start-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8f7a6ca

Please sign in to comment.