Semaphore/lib/routes/index.js

45 lines
792 B
JavaScript
Raw Normal View History

2014-08-24 19:36:34 +02:00
var util = require('../util')
, auth = require('./auth')
2014-08-24 23:00:05 +02:00
, playbooks = require('./playbook/playbooks')
, profile = require('./profile')
2014-08-24 19:36:34 +02:00
exports.router = function(app) {
var templates = require('../templates')(app);
templates.route([
auth,
2014-08-24 23:00:05 +02:00
playbooks
2014-08-24 19:36:34 +02:00
]);
templates.add('homepage')
templates.setup();
app.get('/', layout);
app.all('*', util.authorized);
// Handle HTTP reqs
2014-08-24 23:00:05 +02:00
playbooks.httpRouter(app);
2014-08-24 19:36:34 +02:00
// only json beyond this point
app.get('*', function(req, res, next) {
res.format({
json: function() {
next()
},
html: function() {
layout(req, res);
}
});
});
auth.router(app);
2014-08-24 23:00:05 +02:00
playbooks.router(app);
profile.router(app);
2014-08-24 19:36:34 +02:00
}
function layout (req, res) {
if (res.locals.loggedIn) {
res.render('layout')
} else {
res.render('auth');
}
}