Ghost/core/frontend/services/routing/PreviewRouter.js
Naz 74280cfbea Added "email post" frontend routing
refs https://github.com/TryGhost/Team/issues/953

- Emails posts should be not explorable by the rest of the frontend similarly to the draft or scheduled posts. Email posts should also keep the content gating, so that specific parts of content can still be gated based on the post's visibility setup
- A separate frontend router was chosen to implement this part of the system instead of a moutable express app due to increased complexity to introduce the latter approach.
- All "sent" email-only posts will be accessible through the `/email/:slug/` route
2021-08-13 12:09:11 +04:00

51 lines
1.2 KiB
JavaScript

const ParentRouter = require('./ParentRouter');
const urlUtils = require('../../../shared/url-utils');
const controllers = require('./controllers');
/**
* @description Preview Router.
*/
class PreviewRouter extends ParentRouter {
constructor(RESOURCE_CONFIG) {
super('PreviewRouter');
this.RESOURCE_CONFIG = RESOURCE_CONFIG.QUERY.preview;
// @NOTE: hardcoded, not configureable
this.route = {value: '/p/'};
this._registerRoutes();
}
/**
* @description Register all routes of this router.
* @private
*/
_registerRoutes() {
// REGISTER: prepare context
this.router().use(this._prepareContext.bind(this));
// REGISTER: actual preview route
this.mountRoute(urlUtils.urlJoin(this.route.value, ':uuid', ':options?'), controllers.preview);
}
/**
* @description Prepare context for further middlewares/controllers.
* @param {Object} req
* @param {Object} res
* @param {Function} next
* @private
*/
_prepareContext(req, res, next) {
res.routerOptions = {
type: 'entry',
query: this.RESOURCE_CONFIG,
context: ['preview']
};
next();
}
}
module.exports = PreviewRouter;