-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
49 lines (36 loc) · 1.31 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var express = require('express');
// var bodyParser = require('body-parser');
var consulLib = require('./consulLib.js');
var os = require('os');
var app = express();
var router = express.Router();
//app.use(bodyParser.json());
app.use('/', router);
function getHtContent() {
var isoDate = new Date().toISOString().replace(/T|Z/g, " ");
if (process.env.REGISTER_CONSUL) {
consulLib.putKv('lastRequestDate', isoDate);
}
return isoDate;
}
if (process.env.REGISTER_CONSUL){
consulLib.registerService();
}
router.get('/', function(req, res) {
var htHeader = '<HTML>' +
'<HEAD><STYLE> ' +
'body{ background-color: lightblue; padding-top: 150px; text-align: center; font: 50px monospace; }' +
'</STYLE></HEAD>' +
'<BODY>';
var htContent = getHtContent();
var htFooter = '</BODY></HTML>';
res.send( htHeader +
'<div>1111 - Hostname ' + os.hostname() + '</div>' +
'<div>Time ' + htContent + ' on server</div>' +
'<div><script>document.write("Time " + new Date().toISOString().replace(/T|Z/g, " ") + " on client");</script></div>' +
htFooter).end();
});
router.get('/plain', function(req, res) {
res.send( getHtContent() ).end();
});
app.listen(3000);