mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 16:01:40 +03:00
98f5ae00fc
refs #5091, #9192 - Renderer figures out templates, contexts, and does a render call - Templating is now handled with a single function - Context call is made in the renderer Note: to make this work, all controllers now define a little bit of config, currently stored in res._route. (That's a totally temporary location, as is res._template... when a sensible naming convention reveals itself I'll get rid of the weird _). This exposes a type and for custom routes a template name & default.
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
var path = require('path'),
|
|
express = require('express'),
|
|
middleware = require('./middleware'),
|
|
bodyParser = require('body-parser'),
|
|
renderer = require('../../../controllers/frontend/renderer'),
|
|
brute = require('../../../middleware/brute'),
|
|
|
|
templateName = 'private',
|
|
|
|
privateRouter = express.Router();
|
|
|
|
function _renderer(req, res) {
|
|
// Note: this is super similar to the config middleware used in channels
|
|
// @TODO refactor into to something explicit & DRY this up
|
|
res._route = {
|
|
type: 'custom',
|
|
templateName: templateName,
|
|
defaultTemplate: path.resolve(__dirname, 'views', templateName + '.hbs')
|
|
};
|
|
|
|
// Renderer begin
|
|
// Format data
|
|
var data = {};
|
|
|
|
if (res.error) {
|
|
data.error = res.error;
|
|
}
|
|
|
|
// Render Call
|
|
return 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;
|