-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
56 lines (45 loc) · 1.08 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
const http = require('http')
const hostname = '0.0.0.0'
const port = 3000
var started = false
var ready = false
setTimeout(() => {
started = true
console.log("started up")
}, 10 * 1000)
setTimeout(() => {
ready = true
console.log("ready")
}, 15 * 1000)
const server = http.createServer((req, res) => {
console.log(req.url)
res.statusCode = 200
res.setHeader('Content-Type', 'text/plain')
if (!started) {
console.error("called before startup crashing")
process.exit()
}
else if (req.url == "/health") {
res.end('OK\n')
}
else if (!ready) {
console.error("failed to serve a request")
res.statusCode = 500
res.end('NOT READY\n')
}
else {
res.statusCode = 200
res.setHeader('Content-Type', 'text/plain')
res.end('Hello World\n')
}
})
if (Math.ceil(Math.random() * 3) !== 3) {
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`)
})
}
setTimeout(() => {
server.close()
console.log("server crashed")
}, 2 * 60 * 1000)
setInterval(() => console.log("-- MARK --"), 60 * 1000)