-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
executable file
·49 lines (42 loc) · 1.31 KB
/
main.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
//Required dependencies
var express = require('express');
var bunyan = require('bunyan');
var prettyjson = require('prettyjson');
var moment = require('moment');
var versionInfo = require('./version.js');
var log = bunyan.createLogger({
level: 'trace',
name: 'echo-vcap'
});
var serverStartTime = moment();
var PORT = process.env.PORT || 3003;
var vcapInfo={env: 'dev'};
if(process.env.VCAP_APPLICATION){
vcapInfo = JSON.parse(process.env.VCAP_APPLICATION);
}
//Create express server & socket.io
var app = express();
//app.use(require('express-bunyan-logger')());
function prettyPrintObject(req, rsp, obj){
var options = {
noColor: true
};
var responseString= '<pre>' + prettyjson.render(obj, options) + '</pre>';
rsp.send(responseString);
}
function startServer(err) {
log.trace('Setup express.');
if(err) {
log.error(err);
} else {
app.use('/vcap', (req, rsp) => {prettyPrintObject(req, rsp, vcapInfo);});
app.use('/version', (req, rsp) => {prettyPrintObject(req, rsp, versionInfo);});
app.get('/', function (req, res) {
res.send('Server uptime: ' + moment.duration(moment().diff(serverStartTime)).humanize());
});
app.listen(PORT, '0.0.0.0', function () { //Start Express Server
log.info('VCAP_APPLICATION echo app listening on port ' + PORT);
});
}
}
startServer();