mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-09 21:07:46 +00:00
[next] fix app dir edge functions with basePath (#10465)
x-ref: https://github.com/vercel/vercel/pull/10394
This commit is contained in:
@@ -2344,7 +2344,7 @@ export function normalizeIndexOutput(
|
||||
outputName: string,
|
||||
isServerMode: boolean
|
||||
) {
|
||||
if (outputName !== '/index' && isServerMode) {
|
||||
if (outputName !== 'index' && outputName !== '/index' && isServerMode) {
|
||||
return outputName.replace(/\/index$/, '');
|
||||
}
|
||||
return outputName;
|
||||
@@ -2521,6 +2521,29 @@ function normalizeRegions(regions: Regions): undefined | string | string[] {
|
||||
return newRegions;
|
||||
}
|
||||
|
||||
export function normalizeEdgeFunctionPath(
|
||||
shortPath: string,
|
||||
appPathRoutesManifest: Record<string, string>
|
||||
) {
|
||||
if (
|
||||
shortPath.startsWith('app/') &&
|
||||
(shortPath.endsWith('/page') ||
|
||||
shortPath.endsWith('/route') ||
|
||||
shortPath === 'app/_not-found')
|
||||
) {
|
||||
const ogRoute = shortPath.replace(/^app\//, '/');
|
||||
shortPath = (
|
||||
appPathRoutesManifest[ogRoute] ||
|
||||
shortPath.replace(/(^|\/)(page|route)$/, '')
|
||||
).replace(/^\//, '');
|
||||
|
||||
if (!shortPath || shortPath === '/') {
|
||||
shortPath = 'index';
|
||||
}
|
||||
}
|
||||
return shortPath;
|
||||
}
|
||||
|
||||
export async function getMiddlewareBundle({
|
||||
entryPath,
|
||||
outputDirectory,
|
||||
@@ -2699,27 +2722,19 @@ export async function getMiddlewareBundle({
|
||||
// app/index/page -> index/index
|
||||
if (shortPath.startsWith('pages/')) {
|
||||
shortPath = shortPath.replace(/^pages\//, '');
|
||||
} else if (
|
||||
shortPath.startsWith('app/') &&
|
||||
(shortPath.endsWith('/page') ||
|
||||
shortPath.endsWith('/route') ||
|
||||
shortPath === 'app/_not-found')
|
||||
) {
|
||||
const ogRoute = shortPath.replace(/^app\//, '/');
|
||||
shortPath = (
|
||||
appPathRoutesManifest[ogRoute] ||
|
||||
shortPath.replace(/(^|\/)(page|route)$/, '')
|
||||
).replace(/^\//, '');
|
||||
|
||||
if (!shortPath || shortPath === '/') {
|
||||
shortPath = 'index';
|
||||
}
|
||||
} else {
|
||||
shortPath = normalizeEdgeFunctionPath(shortPath, appPathRoutesManifest);
|
||||
}
|
||||
|
||||
if (routesManifest?.basePath) {
|
||||
shortPath = path.posix
|
||||
.join(routesManifest.basePath, shortPath)
|
||||
.replace(/^\//, '');
|
||||
shortPath = normalizeIndexOutput(
|
||||
path.posix.join(
|
||||
'./',
|
||||
routesManifest?.basePath,
|
||||
shortPath.replace(/^\//, '')
|
||||
),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
worker.edgeFunction.name = shortPath;
|
||||
|
||||
Reference in New Issue
Block a user