Use startServer function

This commit is contained in:
MICHAEL JACKSON 2017-08-18 23:10:04 -07:00
parent 22c5c550be
commit 17f6a6bbe9
1 changed files with 26 additions and 24 deletions

View File

@ -4,32 +4,34 @@ const createApp = require('./server/createApp')
const port = parseInt(process.env.PORT, 10) || 5000 const port = parseInt(process.env.PORT, 10) || 5000
function startServer(id) {
const server = http.createServer(createApp())
// Heroku dynos automatically timeout after 30s. Set our
// own timeout here to force sockets to close before that.
// https://devcenter.heroku.com/articles/request-timeout
server.setTimeout(25000, function (socket) {
const message = `Timeout of 25 seconds exceeded`
socket.end([
'HTTP/1.1 503 Service Unavailable',
'Date: ' + (new Date).toGMTString(),
'Content-Length: ' + Buffer.byteLength(message),
'Content-Type: text/plain',
'Connection: close',
'',
message
].join('\r\n'))
})
server.listen(port, function () {
console.log('Server #%s listening on port %s, Ctrl+C to stop', id, port)
})
}
throng({ throng({
workers: process.env.WEB_CONCURRENCY || 1, workers: process.env.WEB_CONCURRENCY || 1,
lifetime: Infinity, lifetime: Infinity,
grace: 25000, grace: 25000,
start: function (id) { start: startServer
const server = http.createServer(createApp())
// Heroku dynos automatically timeout after 30s. Set our
// own timeout here to force sockets to close before that.
// https://devcenter.heroku.com/articles/request-timeout
server.setTimeout(25000, function (socket) {
const message = `Timeout of 25 seconds exceeded`
socket.end([
`HTTP/1.1 503 Service Unavailable`,
`Date: ${(new Date).toGMTString()}`,
`Content-Type: text/plain`,
`Content-Length: ${Buffer.byteLength(message)}`,
`Connection: close`,
``,
message
].join(`\r\n`))
})
server.listen(port, function () {
console.log('Server #%s listening on port %s, Ctrl+C to stop', id, port)
})
}
}) })