Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix appDir returning 404 in production with "output": "standalone" #43268

Merged
merged 8 commits into from Nov 24, 2022
18 changes: 18 additions & 0 deletions packages/next/build/index.ts
Expand Up @@ -865,6 +865,11 @@ export default async function build(
)

const manifestPath = path.join(distDir, SERVER_DIRECTORY, PAGES_MANIFEST)
const appManifestPath = path.join(
distDir,
SERVER_DIRECTORY,
APP_PATHS_MANIFEST
)

const requiredServerFiles = nextBuildSpan
.traceChild('generate-required-server-files')
Expand All @@ -882,6 +887,7 @@ export default async function build(
files: [
ROUTES_MANIFEST,
path.relative(distDir, manifestPath),
path.relative(distDir, appManifestPath),
ijjk marked this conversation as resolved.
Show resolved Hide resolved
BUILD_MANIFEST,
PRERENDER_MANIFEST,
path.join(SERVER_DIRECTORY, MIDDLEWARE_MANIFEST),
Expand Down Expand Up @@ -2046,6 +2052,7 @@ export default async function build(
dir,
distDir,
pageKeys.pages,
pageKeys.app,
outputFileTracingRoot,
requiredServerFiles.config,
middlewareManifest
Expand Down Expand Up @@ -2761,6 +2768,17 @@ export default async function build(
),
{ overwrite: true }
)
await recursiveCopy(
path.join(distDir, SERVER_DIRECTORY, 'app'),
path.join(
distDir,
'standalone',
path.relative(outputFileTracingRoot, distDir),
SERVER_DIRECTORY,
'app'
),
{ overwrite: true }
)
}

staticPages.forEach((pg) => allStaticPages.add(pg))
Expand Down
10 changes: 10 additions & 0 deletions packages/next/build/utils.ts
Expand Up @@ -1598,6 +1598,7 @@ export async function copyTracedFiles(
dir: string,
distDir: string,
pageKeys: ReadonlyArray<string>,
appPageKeys: readonly string[] | undefined,
tracingRoot: string,
serverConfig: { [key: string]: any },
middlewareManifest: MiddlewareManifest
Expand Down Expand Up @@ -1680,6 +1681,15 @@ export async function copyTracedFiles(
Log.warn(`Failed to copy traced files for ${pageFile}`, err)
})
}
if (appPageKeys) {
for (const page of appPageKeys) {
const pageFile = path.join(distDir, 'server', 'app', `${page}`, 'page.js')
const pageTraceFile = `${pageFile}.nft.json`
await handleTraceFiles(pageTraceFile).catch((err) => {
Log.warn(`Failed to copy traced files for ${pageFile}`, err)
})
}
}
await handleTraceFiles(path.join(distDir, 'next-server.js.nft.json'))
const serverOutputPath = path.join(
outputPath,
Expand Down