forked from aredotna/ervell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·43 lines (31 loc) · 902 Bytes
/
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
require('coffee-register');
require('babel-register')({
extensions: ['.js', '.jsx'],
});
global.Promise = require('bluebird');
const throng = require('throng');
const express = require('express');
const { PORT } = require('./config.coffee');
const WORKERS = process.env.WEB_CONCURRENCY || 1;
const setup = require('./lib/setup.coffee');
const cache = require('./lib/cache.coffee');
const app = express();
const startWorker = (id) => {
console.log(`Started worker ${id}`);
cache.setup(() => {
setup(app);
return app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`);
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;