-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
42 lines (32 loc) · 926 Bytes
/
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
const express = require('express')
const app = express()
const PORT = process.env.PORT || 3000
const APP_NAME = 'callee'
const WAIT_BEFORE_SERVER_CLOSE = parseInt(process.env.WAIT_BEFORE_SERVER_CLOSE) || 10
app.get('/api/ok', (req, res) => {
res.send('ok')
})
app.get('/health', (req, res) => {
if (app.locals.shutdown) {
console.log('unhealthy!!')
res.status(400).end()
return
}
// console.log('healthy :)')
res.send('ok')
})
const server = app.listen(PORT, () => {
console.log('%s server started on :%d', APP_NAME, PORT)
})
process.on('SIGTERM', () => {
console.log('received SIGTERM')
app.locals.shutdown = true
console.log('waiting for %d sec to close server', WAIT_BEFORE_SERVER_CLOSE)
setTimeout(() => {
console.log('calling server close')
server.close(() => {
console.log('server closed, exit')
process.exit(0)
})
}, WAIT_BEFORE_SERVER_CLOSE*1000)
})