forked from imjacobclark/cors-container
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
42 lines (30 loc) · 874 Bytes
/
app.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
'use strict';
const express = require('express');
const cors = require('cors');
const compression = require('compression');
const cluster = require('cluster');
const app = express();
const numCPUs = require('os').cpus().length;
const isMasterWorker = cluster.isMaster && !module.parent;
app.use(compression());
app.set('x-powered-by', false)
function clusterApp(){
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', worker => console.error(`worker ${worker.process.pid} died`));
console.info("cors-container listening on port 3000 with " + numCPUs + " threads.")
}
function listen(){
app.listen(process.env.PORT || 3000);
}
if (isMasterWorker) {
clusterApp();
} else {
if (!module.parent) {
listen();
}
}
app.options('*', cors())
require(__dirname + '/bootstrap')(app);
module.exports = app;