Semaphore/lib/routes/index.js

62 lines
1.2 KiB
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')
, identities = require('./identity/identities')
, jobs = require('./job/jobs')
, hosts = require('./host/hosts')
, tasks = require('./task/tasks')
2014-08-24 19:36:34 +02:00
exports.router = function(app) {
var templates = require('../templates')(app);
templates.route([
auth,
2014-08-25 12:35:49 +02:00
playbooks,
identities,
jobs,
hosts,
tasks
2014-08-24 19:36:34 +02:00
]);
templates.add('homepage')
2014-08-25 01:02:34 +02:00
templates.add('abstract')
2014-08-24 19:36:34 +02:00
templates.setup();
app.get('/', layout);
app.all('*', util.authorized);
// Handle HTTP reqs
2014-08-24 23:00:05 +02:00
playbooks.httpRouter(app);
identities.httpRouter(app);
jobs.httpRouter(app);
hosts.httpRouter(app);
tasks.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);
identities.router(app);
jobs.router(app);
hosts.router(app);
tasks.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');
}
}