-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
51 lines (44 loc) · 1.23 KB
/
server.js
File metadata and controls
51 lines (44 loc) · 1.23 KB
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
var os = require('os');
var express = require('express');
var request = require('request');
var app = express();
app.use(express.static(__dirname + '/public'));
var cache = null;
// cache = redis.createClient({
// host: process.env.REDIS_HOST,
// port: process.env.REDIS_PORT,
// password: process.env.REDIS_PASSWORD
// });
app.get('/', function (req, res) {
res.sendFile(__dirname + '/public/index.html');
});
app.get('/api', function (req, res) {
if (cache) {
cache.incr('requestCount');
}
// request({
// uri: 'http://' + process.env.SERVICE_B_HOST,
// }, function (error, response, body) {
res.send('Hello from service A on ' + os.hostname());
// });
});
app.get('/metrics', function (req, res) {
if (!cache) {
res.send({ requestCount: -1 });
} else {
cache.get('requestCount', function (err, reply) {
res.send({ requestCount: reply });
});
}
});
var port = process.env.PORT || 3000;
var server = app.listen(port, function () {
console.log('Listening on port ' + port);
});
process.on("SIGINT", () => {
process.exit(130 /* 128 + SIGINT */);
});
process.on("SIGTERM", () => {
console.log("Terminating...");
server.close();
});