mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
53d14fd8e3
- Added a wrapper around express.Router to our shared/express util - Also export static and _express - Use this shared util everywhre, meaning express is only used directly in this one file - ATM this file is mostly an experiment / debug helper, it might be removed again later - The aim is to have a minimal framework wrapping express that allows us to: - reduce our usage of express() in favour of Router() - unify some of our duplicated logic - fix some structural issues e.g. Sentry - make it easier to understand the codebase
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
const path = require('path');
|
|
const express = require('../../../../shared/express');
|
|
const middleware = require('./middleware');
|
|
const bodyParser = require('body-parser');
|
|
const routing = require('../../../services/routing');
|
|
const web = require('../../../../server/web');
|
|
const templateName = 'private';
|
|
const privateRouter = express.Router(templateName);
|
|
|
|
function _renderer(req, res) {
|
|
res.routerOptions = {
|
|
type: 'custom',
|
|
templates: templateName,
|
|
defaultTemplate: path.resolve(__dirname, 'views', `${templateName}.hbs`)
|
|
};
|
|
|
|
// Renderer begin
|
|
// Format data
|
|
let 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,
|
|
web.shared.middlewares.brute.privateBlog,
|
|
middleware.authenticateProtection,
|
|
_renderer
|
|
);
|
|
|
|
module.exports = privateRouter;
|
|
module.exports.renderer = _renderer;
|