-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
72 lines (55 loc) · 1.48 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var Express = require('express');
var Colors = require('colors');
var HTTP = require('http');
var URL = require('url');
var app = Express.createServer();
app.configure(function() {
app.use(Express.methodOverride());
app.use(Express.bodyParser());
app.use(app.router);
app.use(Express.static(__dirname + '/www'));
});
app.get('/fetch', function(req, res) {
var remote = URL.parse(req.param('remote'));
var data = '';
var content;
HTTP.get(remote, function(rres) {
rres.on('data', function(rdata) {
data += rdata.toString('utf8');
});
rres.on('end', function(rdata) {
if (rdata)
data += rdata.toString('utf8');
content = JSON.parse(data);
res.write(render(content));
res.end();
});
});
});
app.get('/', function(req, res) {
res.redirect('/index.html');
});
app.listen(9009, function() {
console.log("Argo Server Listening on port 9009".green);
});
function render(object) {
var body = '';
if (Array.isArray(object)) {
body += '[\r\n<ol>\r\n';
for ( var i = 0; i < object.length; i++) {
body += "<li>" + render(object[i]) + "</li>\r\n";
}
body += "</ol>\r\n]\r\n";
} else if (typeof (object) == 'object') {
body += '{\r\n<ul>\r\n';
for ( var i in object) {
body += "<li>" + i + " : " + render(object[i]) + "</li>\r\n";
}
body += "</ul>\r\n}\r\n";
} else if (typeof (object) == 'function') {
body += "[function() ...]";
} else {
body += object;
}
return body;
}