-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
46 lines (40 loc) · 1.34 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
var express = require('express');
var redis = require('redis');
var app = express();
var cache = redis.createClient({
host: process.env.STATS_CACHE_SERVICE_HOST,
port: process.env.STATS_CACHE_SERVICE_PORT,
tls: process.env.REDIS_SSL == "true" ? {
host: process.env.STATS_CACHE_SERVICE_HOST,
port: process.env.STATS_CACHE_SERVICE_PORT,
} : undefined,
password: process.env.REDIS_PASSWORD || undefined
});
app.get('/stats', function (req, res) {
console.log('request for stats received with kubernetes-route-as header: %s', req.get('kubernetes-route-as'));
cache.get('todosCreated', function (err, created) {
cache.get('todosCompleted', function (err, completed) {
cache.get('todosDeleted', function (err, deleted) {
res.send({
todosCreated: created || 0,
todosCompleted: completed || 0,
todosDeleted: deleted || 0
});
});
});
});
});
var port = process.env.PORT || 3001;
var server = app.listen(port, function () {
console.log('Listening on port ' + port);
});
process.on("SIGINT", () => {
process.exit(130 /* 128 + SIGINT */);
});
process.on("SIGTERM", () => {
bus.close();
cache.quit();
server.close(() => {
process.exit(143 /* 128 + SIGTERM */);
});
});