-
Notifications
You must be signed in to change notification settings - Fork 11
/
web.js
118 lines (91 loc) · 2.67 KB
/
web.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
var express = require('express');
var app = express.createServer(express.logger());
app.use(express.static(__dirname + '/static'));
app.use(express.bodyParser());
app.register('.html',require('jqtpl').express);
app.set('view options',{layout:false});
var index = 0;
var messages = {
};
var user_re = "([a-z\.0-9]+)";
app.post('/msg/', function(request, response) {
var msg = request.body;
var user;
console.log('Send: ' + JSON.stringify(msg));
if (!msg['dest']) {
console.log("User name not specified");
response.send('Must specify user name', 400);
return;
}
user = msg['dest'];
if (!messages[user]) {
messages[user] = [];
}
messages[user].push(msg);
console.log("User " + user + " now has " + messages[user].length + " messages");
response.send("OK");
});
app.get('/msg/:user' + user_re, function(request, response) {
var msg;
var user;
console.log('Recv: ' + request.params.user);
user = request.params.user;
if (!messages[user]) {
response.send("No messages", 404);
return;
}
if (!messages[user].length) {
response.send("No messages", 404);
return;
}
msg = messages[user].pop();
console.log("User " + user + " now has " + messages[user].length + " messages");
console.log("Returning message " + JSON.stringify(msg));
response.send(JSON.stringify(msg));
});
app.post('/reset', function(request, response) {
messages = {};
response.send("OK");
});
app.get('/', function(request, response) {
var local_src = "/static/js";
var svn_src = "http://svn.resiprocate.org/rep/ietf-drafts/fluffy/roap_demo";
var params = {
peerconnection_src:local_src,
test_src:local_src
};
console.log(request.query);
if (request.query['pc'] === "svn" ){
console.log("Using peerconnection from svn");
params.peerconnection_src = svn_src;
}
if (request.query['test'] === "svn"){
params.test_src = svn_src;
}
console.log(params);
response.render("demo.html", params);
});
app.get("/mozdemoa/:user" + user_re + "/:target" + user_re, function(request, response) {
var params = {
me: request.params.user,
them: request.params.target,
start: false
};
response.render("mozdemo.html", params);
});
app.get("/mozdemoc/:user" + user_re + "/:target" + user_re, function(request, response) {
var params = {
me: request.params.user,
them: request.params.target,
start: true
};
response.render("mozdemo.html", params);
});
app.get("/mozdemo", function(request, response) {
var to_uri = "/mozdemoa/" + ++index + "/" + ++index;
response.redirect(to_uri);
});
var port = process.env.PORT || 3000;
app.listen(port, function() {
console.log("Listening on " + port);
});