Ghost/core/server/apps/private-blogging/lib/router.js
Katharina Irrgang 13cccfa9ee
Dynamic Routing Beta: Refactor res.routerOptions (#9705)
refs #9601

- sort out `res._route` vs. `res.locals.routerOptions`
- it was super hard to maintain two different objects
2018-06-26 01:12:50 +02:00

46 lines
1.1 KiB
JavaScript

const path = require('path'),
express = require('express'),
middleware = require('./middleware'),
bodyParser = require('body-parser'),
routing = require('../../../services/routing'),
brute = require('../../../web/middleware/brute'),
templateName = 'private',
privateRouter = express.Router();
function _renderer(req, res) {
res.routerOptions = {
type: 'custom',
templates: templateName,
defaultTemplate: path.resolve(__dirname, 'views', templateName + '.hbs')
};
// Renderer begin
// Format data
var data = {};
if (res.error) {
data.error = res.error;
}
// Render Call
return routing.helpers.renderer(req, res, 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;