Skip to content

Commit

Permalink
Create static JSON config file for standalone server output
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Mar 2, 2025
1 parent 0b699b1 commit 29e5f87
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/next/src/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1673,15 +1673,19 @@ export async function copyTracedFiles(
}

await handleTraceFiles(path.join(distDir, 'next-server.js.nft.json'))
const serverOutputPath = path.join(
outputPath,
path.relative(tracingRoot, dir),
'server.js'

const serverOutputDir = path.join(outputPath, path.relative(tracingRoot, dir))

await fs.mkdir(serverOutputDir, { recursive: true })

const NEXT_CONFIG_JSON = 'next.config.json'
await fs.writeFile(
path.join(serverOutputDir, NEXT_CONFIG_JSON),
JSON.stringify(nextConfig, undefined, 4)
)
await fs.mkdir(path.dirname(serverOutputPath), { recursive: true })

await fs.writeFile(
serverOutputPath,
path.join(serverOutputDir, 'server.js'),
`${
moduleType
? `performance.mark('next-start');
Expand All @@ -1703,7 +1707,7 @@ const currentPort = parseInt(process.env.PORT, 10) || 3000
const hostname = process.env.HOSTNAME || '0.0.0.0'
let keepAliveTimeout = parseInt(process.env.KEEP_ALIVE_TIMEOUT, 10)
const nextConfig = ${JSON.stringify(nextConfig)}
const nextConfig = require(path.join(dir, '${NEXT_CONFIG_JSON}'))
process.env.__NEXT_PRIVATE_STANDALONE_CONFIG = JSON.stringify(nextConfig)
Expand Down

0 comments on commit 29e5f87

Please sign in to comment.