-
Notifications
You must be signed in to change notification settings - Fork 339
/
server.js
54 lines (45 loc) · 1.57 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
48
49
50
51
52
53
54
// use the express framework
var express = require('express');
var app = express();
var fs = require('fs');
var code_hash = fs.readFileSync('code_hash.txt','utf8');
console.log (code_hash);
console.log('The IPADDRESS is:', process.env.IP);
console.log('The message is:', process.env.AZ);
console.log('The hash is: %s', code_hash);
var ipaddress = process.env.IP;
var message = process.env.AZ;
// morgan: generate apache style logs to the console
var morgan = require('morgan')
app.use(morgan('combined'));
// express-healthcheck: respond on /health route for LB checks
app.use('/health', require('express-healthcheck')());
// main route
app.get('/', function (req, res) {
res.set({
'Content-Type': 'text/plain'
})
res.send(`Node.js backend: Hello! from ${message} commit ${code_hash}`);
// res.send(`Hello World! from ${ipaddress} in AZ-${az} which has been up for ` + process.uptime() + 'ms');
});
app.get('/nodejs', function (req, res) {
res.set({
'Content-Type': 'text/plain'
})
res.send(`Node.js backend: Hello! from ${message} commit ${code_hash}`);
// res.send(`Hello World! from ${ipaddress} in AZ-${az} which has been up for ` + process.uptime() + 'ms');
});
app.get('/nodejs/api', function (req, res) {
res.send({
from: 'Node.js backend',
message: message,
commit: code_hash
});
});
// health route - variable subst is more pythonic just as an example
var server = app.listen(3000, function() {
var port = server.address().port;
console.log('Example app listening on port %s!', port);
});
// export the server to make tests work
module.exports = server;