-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
79 lines (76 loc) · 1.63 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
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 app = express();
const http = require('http')
const hostname = require('os').hostname();
let healthy = true;
let working = false;
const port = 80
class CpuBurner {
constructor() {
this.toggle = false;
}
start() {
this.toggle = true;
return
}
stop() {
this.toggle = false;
return
}
}
const cpuBurn = new CpuBurner();
app.set('view engine', 'jade')
app.set('views', './views')
app.listen(port, () => {
console.log(`listening to port ${port}`);
})
app.get('/health', async (req, res) => {
if (healthy) {
res.status(200);
} else {
res.status(500);
}
res.render('health', { healthy: healthy })
})
app.get('/', async (req, res) => {
res.render('index', {
hostname: hostname,
healthy: healthy,
working: working
})
res.status(200)
})
app.get('/startLoad', async (req, res) => {
working = true;
res.render('index', {
hostname: hostname,
healthy: healthy,
working: working
})
cpuBurn.start();
})
app.get('/stopLoad', async (req, res) => {
working = false;
res.render('index', {
hostname: hostname,
healthy: healthy,
working: working
})
cpuBurn.stop();
})
app.get('/makeUnhealthy', async (req, res) => {
healthy = false;
res.render('index', {
hostname: hostname,
healthy: healthy,
working: working
})
})
app.get('/makeHealthy', async (req, res) => {
healthy = true;
res.render('index', {
hostname: hostname,
healthy: healthy,
working: working
})
})