-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
42 lines (32 loc) · 1.04 KB
/
index.js
File metadata and controls
42 lines (32 loc) · 1.04 KB
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
var os = require("os");
var express = require('express');
var exphbs = require('express-handlebars');
var request = require('request'),proxyUrl = 'http://<public_slave>:4140';
var app = express();
var cid = os.hostname();
var hostname = process.env.HN;
var app_name = process.env.APP;
var url = 'http://'+app_name+'/api/info';
app.use(express.static(__dirname + '/public'));
app.engine('handlebars', exphbs({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');
app.get('/', function (req, res) {
res.render('home', { cid: cid, hostname: hostname });
});
app.get('/api/info', function (req, res) {
var result = {};
result['cid'] = cid;
result['hostname'] = hostname;
res.contentType('application/json');
res.send(JSON.stringify(result));
});
app.get('/api/connect', function (req, res) {
var json = {};
request(url,{proxy: proxyUrl}, function (error, response, body) {
if (!error && response.statusCode == 200) {
res.contentType('application/json');
res.send(body);
}
})
});
app.listen(3000);