Skip to content

Commit

Permalink
feat(server): add /status route for JSON form of data sent to UI
Browse files Browse the repository at this point in the history
fixes #57
  • Loading branch information
geraintwhite committed Feb 12, 2016
1 parent f6965a7 commit 71499b3
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,15 @@ Server.prototype.serve = function (req, res) {
self.build_manager.rerun(res, parseInt(url_parts.query.rebuild));

} else { // Send the HTML
var html = self.render();
var html = self.templates.index(self.status());
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(html);
}

} else if (url_parts.pathname === '/status') {
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSON.stringify(self.status()));

} else { // Serve static files
logging.log('Serving file: ' + url_parts.pathname);
fileserver.serve(req, res, function(e) {
Expand All @@ -167,12 +171,12 @@ Server.prototype.serve = function (req, res) {
};

/**
* Generate DOM to send to UI of builds dashboard
* @name Server.render
* Generate data to send to builds dashboardself.templates.index)(
* @name Server.status
* @function
*/

Server.prototype.render = function () {
Server.prototype.status = function () {
var self = this;

// Sort builds
Expand All @@ -187,11 +191,11 @@ Server.prototype.render = function () {
self.get_build(self.build_manager.current) :
builds.length ? builds[0] : {empty: true, data: {}};

return self.templates.index({
return {
status: self.build_manager.running ? self.STATUS.RUNNING : self.STATUS.READY,
builds: builds,
current: current
});
};
};

/**
Expand Down

0 comments on commit 71499b3

Please sign in to comment.