-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
72 lines (58 loc) · 1.99 KB
/
app.js
File metadata and controls
72 lines (58 loc) · 1.99 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
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 app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var response = {};
var clients = 0;
var routes = {};
// build an on disconnect to remove routes from list.
io.on('connection', function(socket) {
console.log("a new server is online");
clients++;
socket.on('response', function(result) {
console.log(result);
if (response !== null) {
response.send(result); // in theory return what a connected client returns;
response = {};
}
});
// We should theoretically have a list of all of our routes for a particular socket
socket.on('routes', function(results) {
console.log("routes response");
for (result in results){
routes[results[result]] = socket;
}
});
io.emit('routes', {});
});
app.get('/sitemap', function(req, res) {
console.log(Object.keys(routes));
var response_string = "<html><body>";
var keys = Object.keys(routes);
for (key in keys){
response_string = response_string + '<a href=\'http://192.168.0.13:3000' + keys[key] + '\'>' + keys[key] + '</a><br/>';
}
response_string = response_string + '</body></html>';
res.send(response_string);
});
app.get('*', function(req, res) {
console.log(req.url);
io.emit('get', {
route: req.url
}); // Emit to everyone that is calling
response = res;
});
app.post('*', function(req, res) {
console.log(req.url);
// in theory we should know our routes,
// and at this point, we send the data to the right route.
// this way we don't have any issues with storing data across the entire connection network
// which may or may not be a security issue (storing everywhere).
io.emit('post', {
route: req.url,
data : req.data // this probably needs fixing, research
}); // Emit to everyone that is calling
response = res;
});
http.listen(3000, function() {
console.log('listening on *:3000');
});