forked from stepro/service-a
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
47 lines (40 loc) · 1.19 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
47
var os = require('os');
var express = require('express');
var request = require('request');
var contextful = require('./contextful');
var redis = require('redis').createClient(process.env.REDIS_PORT, process.env.REDIS_HOST, {
auth_pass: process.env.REDIS_KEY,
tls: {
servername: process.env.REDIS_HOST
}
});
var app = express();
app.use(express.static(__dirname + '/public'));
app.get('/', function (req, res) {
res.sendFile(__dirname + '/public/index.html');
});
app.get('/api', function (req, res) {
redis.incr('requestCount');
request({
uri: 'http://service-b',
headers: contextful.from(req)
}, function (error, response, body) {
res.send('Hello from service A container ' + os.hostname() + ' and ' + body);
});
});
app.get('/metrics', function (req, res) {
redis.get('requestCount', function (err, reply) {
res.send({ requestCount: reply });
});
});
var port = 80;
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();
});