Unverified Commit cbbfebf5 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Handle basePath app-dir minimal case (#53189)

This ensures even when the invoke headers aren't present we properly
handle `basePath`.

Tested against
https://tmp-contents-idtza0iup-vtest314-ijjk-testing.vercel.app/hello/world

Fixes:
https://github.com/vercel/vercel/actions/runs/5660473696/job/15342856245?pr=10249#step:9:563
parent 7160af3d
......@@ -720,11 +720,11 @@ export default abstract class Server<ServerOptions extends Options = Options> {
addRequestMeta(req, '_nextHadBasePath', true)
}
const useMatchedPathHeader =
this.minimalMode && typeof req.headers['x-matched-path'] === 'string'
// TODO: merge handling with x-invoke-path
if (
this.minimalMode &&
typeof req.headers['x-matched-path'] === 'string'
) {
if (useMatchedPathHeader) {
try {
if (this.hasAppDir) {
// ensure /index path is normalized for prerender
......@@ -738,7 +738,8 @@ export default abstract class Server<ServerOptions extends Options = Options> {
// x-matched-path is the source of truth, it tells what page
// should be rendered because we don't process rewrites in minimalMode
let matchedPath = normalizeRscPath(
new URL(req.headers['x-matched-path'], 'http://localhost').pathname,
new URL(req.headers['x-matched-path'] as string, 'http://localhost')
.pathname,
this.hasAppDir
)
......@@ -1023,14 +1024,14 @@ export default abstract class Server<ServerOptions extends Options = Options> {
// when x-invoke-path is specified we can short short circuit resolving
// we only honor this header if we are inside of a render worker to
// prevent external users coercing the routing path
const matchedPath = req.headers['x-invoke-path'] as string
if (
!(req.headers['x-matched-path'] && this.minimalMode) &&
const invokePath = req.headers['x-invoke-path'] as string
const useInvokePath =
!useMatchedPathHeader &&
process.env.NEXT_RUNTIME !== 'edge' &&
process.env.__NEXT_PRIVATE_RENDER_WORKER &&
matchedPath
) {
invokePath
if (useInvokePath) {
if (req.headers['x-invoke-status']) {
const invokeQuery = req.headers['x-invoke-query']
......@@ -1054,7 +1055,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
return this.renderError(err, req, res, '/_error', parsedUrl.query)
}
const parsedMatchedPath = new URL(matchedPath || '/', 'http://n')
const parsedMatchedPath = new URL(invokePath || '/', 'http://n')
const invokePathnameInfo = getNextPathnameInfo(
parsedMatchedPath.pathname,
{
......@@ -1139,6 +1140,14 @@ export default abstract class Server<ServerOptions extends Options = Options> {
return
}
// ensure we strip the basePath when not using an invoke header
if (!(useMatchedPathHeader || useInvokePath) && pathnameInfo.basePath) {
parsedUrl.pathname = removePathPrefix(
parsedUrl.pathname,
pathnameInfo.basePath
)
}
res.statusCode = 200
return await this.run(req, res, parsedUrl)
} catch (err: any) {
......
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