Files
Shu DingandGitHub 83b774eeb6 Fix standalone mode with appDir running in a single process (#49116)
Fixes #49055, fixes #48918. 

App dir will always require the server to run in the workers mode, so it
can keep a separate Node.js process for pages. This PR updates the
standalone server to initialize a "standalone server" (which works
similar to `start-server`), and changes the tracked files to include
Jest worker.
2023-05-04 05:55:05 +02:00

44 lines
1.0 KiB
JavaScript

const NextServer = require('next/dist/server/next-server').default
const defaultNextConfig =
require('next/dist/server/config-shared').defaultConfig
const http = require('http')
process.on('SIGTERM', () => process.exit(0))
process.on('SIGINT', () => process.exit(0))
let handler
const server = http.createServer(async (req, res) => {
try {
await handler(req, res)
} catch (err) {
console.error(err)
res.statusCode = 500
res.end('Internal Server Error')
}
})
const currentPort = parseInt(process.env.PORT, 10) || 3000
server.listen(currentPort, (err) => {
if (err) {
console.error('Failed to start server', err)
process.exit(1)
}
const nextServer = new NextServer({
hostname: 'localhost',
port: currentPort,
customServer: true,
dev: false,
conf: {
...defaultNextConfig,
distDir: '.next',
experimental: {
...defaultNextConfig.experimental,
},
},
})
handler = nextServer.getRequestHandler()
console.log('Listening on port', currentPort)
})