-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
30 lines (23 loc) · 885 Bytes
/
index.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
var request = require('request-promise-native');
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
const GREETING_URL = process.env.GREETING_URL;
const NAME_URL = process.env.NAME_URL;
const os = require('os');
const hostname = os.hostname();
if (!GREETING_URL) {
throw new Error('Process requires that environment variable GREETING_URL be passed');
}
if (!NAME_URL) {
throw new Error('Process requires that environment variable NAME_URL be passed');
}
app.get('*', async function(req, res) {
res.send(`From ${hostname}: ` + await request(GREETING_URL) + ' ' + await request(NAME_URL));
});
app.listen(port, () => console.log(`Listening on port ${port}!`));
// This causes the process to respond to "docker stop" faster
process.on('SIGTERM', function() {
console.log('Received SIGTERM, shutting down');
app.close();
});