-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
36 lines (32 loc) · 1.02 KB
/
server.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
const init = function () {
let http = require("http");
let consign = require("consign");
let io = require("socket.io")();
let app = require("express")();
app.ROOT_PATH = __dirname;
require("./config-express")(app);
consign()
.include("app/routes")
.into(app);
let server = http.createServer(app);
io.attach(server);
console.log(`SERVIDOR NA PORTA ${(process.env.NODE_ENV.trim() == 'production' ? 3000 : 80)}`)
server.listen((process.env.NODE_ENV.trim() == 'production' ? 3000 : 80));
}
if (process.env.NODE_ENV.trim() === "production") {
const cluster = require('cluster');
const numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
console.log(`Master ${process.pid} is running`);
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', (worker, code, signal) => {
console.log(`worker ${worker.process.pid} died`);
});
} else {
init();
}
} else {
init();
}