Skip to content
This repository has been archived by the owner on Jul 25, 2018. It is now read-only.

Commit

Permalink
Add api.
Browse files Browse the repository at this point in the history
  • Loading branch information
mythmon committed May 7, 2013
1 parent ea000a4 commit 8b71195
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
7 changes: 2 additions & 5 deletions app/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ exports.setUrl = function(url, screenName) {
config.resetTime);

p.resolve(content);
});
}, p.reject);

return p;
};
Expand All @@ -166,9 +166,6 @@ exports.reset = function(screenName) {
}

if (screen === undefined) {
screen = screens[nextScreen];
nextScreen = (nextScreen + 1) % screens.length;

_.each(screens, function(screen) {
screen.content = getDefaultContent();
sendScreenChanged(screen);
Expand Down Expand Up @@ -247,7 +244,7 @@ function contentForUrl(url) {
// redirect, handle it.
console.log('redirect ' + headers.location);
var newP = contentForUrl(headers.location);
newP.then(p.resolve, p.reject);
newP.then(p.resolve, function(data) { p.reject(data, true); });
return;
}

Expand Down
36 changes: 34 additions & 2 deletions app/web.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,48 @@
var express = require('express');
var http = require('http');
var config = require('./config');
var manager = require('./manager');


var app = express();

app.set('port', config.web.port);

app.configure(function() {
app.use('/', express.static(__dirname + '/../static'));

app.post('/api/reset', function(req, res) {
var screenName = req.query.screen || undefined;

manager.reset(screenName);

res.status(201);
res.send('');
});

app.post('/api/sendurl', function(req, res) {
var p;
var url = req.query.url;
var screenName = req.query.screen || undefined;

if (url === undefined) {
res.json(400, {error: 'URL is required.'});
return;
}

p = manager.setUrl(url, screenName);
//p.then(res.json.bind(res, 200), res.json.bind(res, 500));
p.then(
function(obj) {
res.json(200, obj);
},
function(obj) {
res.json(500, obj);
}
);
});


app.use('/', express.static(__dirname + '/../static'));

exports.server = http.createServer(app).listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
});

0 comments on commit 8b71195

Please sign in to comment.