Ghost/core/server/apps/private-blogging/lib/router.js
Hannah Wolfe abaf0461cf Highlighted routes, controllers & renderers
refs #5091, refs #9192

- There are several theme template "renderers" all over the codebase
- Some are in apps, and were called "controllers"
- One is in error handling
- All of them now have comments marking out how they share logic/steps
- Other comments describe routes & controllers where they live
2017-11-08 09:45:12 +00:00

49 lines
1.3 KiB
JavaScript

var path = require('path'),
express = require('express'),
middleware = require('./middleware'),
bodyParser = require('body-parser'),
templates = require('../../../controllers/frontend/templates'),
setResponseContext = require('../../../controllers/frontend/context'),
brute = require('../../../middleware/brute'),
templateName = 'private',
defaultTemplate = path.resolve(__dirname, 'views', templateName + '.hbs'),
privateRouter = express.Router();
function _renderer(req, res) {
// Renderer begin
// Format data
var data = {};
if (res.error) {
data.error = res.error;
}
// Context
setResponseContext(req, res);
// Template
res.template = templates.pickTemplate(templateName, defaultTemplate);
// Render Call
return res.render(res.template, data);
}
// password-protected frontend route
privateRouter.route('/')
.get(
middleware.isPrivateSessionAuth,
_renderer
)
.post(
bodyParser.urlencoded({extended: true}),
middleware.isPrivateSessionAuth,
brute.privateBlog,
middleware.authenticateProtection,
_renderer
);
module.exports = privateRouter;
module.exports.renderer = _renderer;