-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathindex.js
executable file
·70 lines (55 loc) · 1.48 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* eslint-disable no-console */
require('source-map-support').install()
require('regenerator-runtime/runtime')
require('newrelic')
require('sqreen')
/*
* Apollo client uses Promise.prototype.finally,
* but this isn't automatically polyfilled into
* our app because Babel only polyfills features
* if they're actually being used in our client code
* (not in node_modules I guess).
*
* This manually includes the polyfill so that apollo
* works.
*/
require('core-js/fn/promise/finally')
if (process.env.NODE_ENV === 'development') {
require('coffee-register')
require('@babel/register')({
extensions: ['.ts', '.js', '.tsx', '.jsx'],
})
}
global.Promise = require('bluebird')
const throng = require('throng')
const express = require('express')
const CONFIG = require('./config.coffee')
const WORKERS = process.env.WEB_CONCURRENCY || 1
const PORT = process.env.PORT || CONFIG.PORT
const setup = require('./lib/setup.coffee')
const cache = require('./lib/cache.coffee')
const app = express()
const startWorker = id => {
console.log(`Started worker ${id}`)
cache.connect()
setup(app)
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`)
// eslint-disable-next-line
return typeof process.send === 'function'
? process.send('listening')
: void 0
})
process.on('SIGTERM', () => {
console.log(`Worker ${id} exiting`)
process.exit()
})
}
throng(
{
workers: WORKERS,
lifetime: Infinity,
},
startWorker
)
module.exports = app