-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
78 lines (61 loc) · 1.97 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const express = require('express');
const cors = require("cors");
const bodyParser = require('body-parser');
const cluster = require('cluster');
const os = require('os');
const readLastLines = require('read-last-lines');
const app = express();
const port = 3002;
const numCpu = os.cpus().length;
app.use(cors());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.post('/', (req, res) => {
console.log(req.body, new Date());
for (let i = 0; i < 1e8; i++) {
}
console.log(new Date());
res.send({code: 200, pid: process.pid})
//cluster.Worker.kill();
});
app.get('/', (req, res) => {
console.log(req.body, new Date());
for (let i = 0; i < 1e8; i++) {
}
console.log(new Date());
res.send({code: 200, pid: process.pid, name: "Test"})
//cluster.Worker.kill();
});
app.get('/authe/signin', (req, res) => {
console.log(req.body, new Date());
for (let i = 0; i < 1e8; i++) {
}
console.log(new Date());
res.send({code: 200, pid: process.pid})
//cluster.Worker.kill();
});
app.get('/cpu', (req, res) => {
res.send({code: 200, numOfCpu: numCpu, isMaster: cluster.isMaster})
});
app.get('/err-logs', (req, res) => {
const startTime = new Date();
readLastLines.read('./logs/err.log', 10)
.then((lines) => {
res.send({Logs: lines, Time: new Date() - startTime }).json()
}).catch(err=>{
res.send(err)
})
});
// if (cluster.isMaster) {
// console.log({numCpu});
// for (let i = 0; i < numCpu; i++) {
// cluster.fork();
// }
// // cluster.on('exit', (worker, code, signal)=>{
// // console.log(`worker ${worker.process.pid} died`);
// // cluster.fork() // crete new one after exit 1
// // })
// }else{
// app.listen(port, () => { console.log(`server ${process.pid} and app listening on port!`, port) });
// }
app.listen(port, () => { console.log(`server ${process.pid} and app listening on port!`, port) });