Unverified Commit 9dbd8d77 authored by AdamKatzDev's avatar AdamKatzDev Committed by GitHub

feat(standalone): allow configuring KEEP_ALIVE_TIMEOUT via env var (#46052)

Resolves #39689, partially resolves #28642 (see notes below)
Inspired by #44627

In #28642 it was also asked to expose `server.headersTimeout`, but it is
probably not needed for most use cases and not implemented even in `next
start`. It was needed to change this option before
https://github.com/nodejs/node/issues/27363.
There also exists a rare bug that is described here
https://github.com/nodejs/node/pull/32329#issuecomment-614119125. To fix
this exposing `server.headersTimeout` might be required both in
`server.js` and in `next start`.
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 539cca85
...@@ -1935,7 +1935,15 @@ const server = http.createServer(async (req, res) => { ...@@ -1935,7 +1935,15 @@ const server = http.createServer(async (req, res) => {
}) })
const currentPort = parseInt(process.env.PORT, 10) || 3000 const currentPort = parseInt(process.env.PORT, 10) || 3000
const hostname = process.env.HOSTNAME || 'localhost' const hostname = process.env.HOSTNAME || 'localhost'
const keepAliveTimeout = parseInt(process.env.KEEP_ALIVE_TIMEOUT, 10);
if (
!Number.isNaN(keepAliveTimeout) &&
Number.isFinite(keepAliveTimeout) &&
keepAliveTimeout >= 0
) {
server.keepAliveTimeout = keepAliveTimeout
}
server.listen(currentPort, (err) => { server.listen(currentPort, (err) => {
if (err) { if (err) {
console.error("Failed to start server", err) console.error("Failed to start server", err)
......
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