-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
51 lines (39 loc) · 1.26 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
/* eslint-disable */
if (process.env.NODE_ENV === "production" || process.env.NODE_ENV === "staging") {
require("newrelic");
require("@newrelic/native-metrics");
}
const config = require("config");
const compression = require('compression')
const Express = require("express");
const fs = require("fs");
const logger = require("./utils/logger");
const cluster = require('cluster');
const numCPUs = require('os').cpus().length;
const app = new Express();
const port = process.env.PORT || config.get("DefaultPort");
if (cluster.isMaster) {
logger.info(`[${config.get("ServiceName")}] - Master ${process.pid} is running`);
// Fork workers.
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}
} else {
app.use(compression());
global.logger = logger;
app.get("/ping", (req, res) => {
res.status(200).send({payload: "pong"});
});
fs.readdirSync("./modules")
.filter(file => (file.indexOf(".") !== 0))
.forEach((file) => {
require(`./modules/${file}/${file}.routes.js`)(app); // eslint-disable-line
});
app.listen(port, (error) => {
if (error) {
logger.error("Error");
} else {
logger.info(`[${config.get("ServiceName")}] - Running on port ${port}`);
}
});
}