-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
35 lines (29 loc) · 803 Bytes
/
server.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
'use strict';
var http = require('http');
var PORT = 3000;
var fail = false;
var server = http.createServer(function(req, res) {
if (req.url === '/fail') {
fail = true;
} else if (req.url === '/restore') {
fail = false;
} else if (req.url === '/healthcheck') {
if (fail) {
res.statusCode = 503;
return res.end('Something is failing');
} else {
return res.end('Test server is working');
}
}
var envList = Object.keys(process.env).reduce(function(memo, key) {
return memo += key + ': ' + process.env[key] + '\n';
}, '');
res.end('It works! Environment:\n========================\n' + envList);
});
function terminationHandler() {
fail = true;
}
process.on('SIGTERM', terminationHandler);
server.listen(PORT, function() {
console.log('Server listening on ' + PORT);
});