Add the events controller

This commit is contained in:
Paul van Tilburg 2012-02-09 10:24:40 +01:00
parent 227464270e
commit 7a78be42c4
1 changed files with 24 additions and 1 deletions

25
app.js
View File

@ -159,12 +159,35 @@ app.configure('production', function() {
app.use(express.errorHandler());
});
// Server the main index file statically for now.
app.get('/', function(req, res) {
res.redirect('/index.html');
});
// The events controller: accessed through AJAX long-poll requests by the
// main page for getting new events.
app.get('/events', function(req, res) {
var u = url.parse(req.url, true);
if (!u.query) {
res.send(null, 400);
return;
}
var timestamp = u.query.timestamp || 0,
requestId = lastRequestId++,
event = nextEvent(timestamp);
if (!event) {
pause(timestamp, req, res, requestId);
}
else {
res.send(event);
res.end();
console.log("[" + requestId + "] direct sent " + JSON.stringify(event));
}
});
// The retrieval controller: accessed through AJAX requests by the main
// page for getting/setting the state (positions) of the draggables.
app.get('/draggables', function(req, res) {