This repository was archived by the owner on Jan 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
49 lines (37 loc) · 1.43 KB
/
app.js
File metadata and controls
49 lines (37 loc) · 1.43 KB
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
const cluster = require('cluster');
const dotenv = require('dotenv');
const express = require('express');
const favicon = require('serve-favicon');
const http = require('http');
const os = require('os');
const path = require('path');
const numCPUs = process.env.WEB_CONCURRENCY || 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`);
cluster.fork();
});
} else {
const app = express();
const server = http.createServer(app);
dotenv.config({ path: path.join(__dirname, '.env') });
const PORT = process.env.PORT || 3000;
const companyRouteController = require('./routes/companyRoute');
const indexRouteController = require('./routes/indexRoute');
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(express.static(path.join(__dirname, 'public')));
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use((req, res, next) => {
req.query = (req.query && typeof req.query == 'object' ? req.query : {});
next();
});
app.use('/', indexRouteController);
app.use('/company', companyRouteController);
server.listen(PORT, () => {
console.log(`Server is on port ${PORT} as Worker ${cluster.worker.id} running @ process ${cluster.worker.process.pid}`);
});
}