Skip to content

Commit

Permalink
fix: redirect logic for App Render
Browse files Browse the repository at this point in the history
Include the basePath to the fetchUrl to ensure the
relative URL matches the app when deployed under a basePath.

- Fixes #58570
  • Loading branch information
Colton Ehrman committed Jan 3, 2024
1 parent f969719 commit b7919b6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/next/src/server/app-render/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ async function createRedirectRenderResult(
req: IncomingMessage,
res: ServerResponse,
redirectUrl: string,
basePath: string,
staticGenerationStore: StaticGenerationStore
) {
res.setHeader('x-action-redirect', redirectUrl)
Expand All @@ -158,7 +159,7 @@ async function createRedirectRenderResult(
const host = req.headers['host']
const proto =
staticGenerationStore.incrementalCache?.requestProtocol || 'https'
const fetchUrl = new URL(`${proto}://${host}${redirectUrl}`)
const fetchUrl = new URL(`${proto}://${host}${basePath}${redirectUrl}`)

if (staticGenerationStore.revalidatedTags) {
forwardedHeaders.set(
Expand Down Expand Up @@ -612,6 +613,7 @@ To configure the body size limit for Server Actions, see: https://nextjs.org/doc
req,
res,
redirectUrl,
ctx.renderOpts.basePath,
staticGenerationStore
),
}
Expand Down

0 comments on commit b7919b6

Please sign in to comment.