2017-08-19 00:32:57 +00:00
|
|
|
const http = require('http')
|
2017-03-26 06:53:54 +00:00
|
|
|
const throng = require('throng')
|
2017-08-19 00:32:57 +00:00
|
|
|
const createApp = require('./server/createApp')
|
2017-03-26 06:53:54 +00:00
|
|
|
|
|
|
|
const port = parseInt(process.env.PORT, 10) || 5000
|
|
|
|
|
|
|
|
throng({
|
|
|
|
workers: process.env.WEB_CONCURRENCY || 1,
|
2017-08-13 00:23:40 +00:00
|
|
|
lifetime: Infinity,
|
2017-08-17 18:56:57 +00:00
|
|
|
grace: 25000,
|
2017-08-13 00:23:40 +00:00
|
|
|
start: function (id) {
|
2017-08-19 00:32:57 +00:00
|
|
|
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`))
|
|
|
|
})
|
2017-08-13 00:23:40 +00:00
|
|
|
|
|
|
|
server.listen(port, function () {
|
|
|
|
console.log('Server #%s listening on port %s, Ctrl+C to stop', id, port)
|
|
|
|
})
|
|
|
|
}
|
2017-03-26 06:53:54 +00:00
|
|
|
})
|