Ghost/core/server/services/routing/PreviewRouter.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

30 lines
673 B
JavaScript

const ParentRouter = require('./ParentRouter');
const urlService = require('../url');
const controllers = require('./controllers');
class PreviewRouter extends ParentRouter {
constructor() {
super('PreviewRouter');
this.route = {value: '/p/'};
this._registerRoutes();
}
_registerRoutes() {
this.router().use(this._prepareContext.bind(this));
this.mountRoute(urlService.utils.urlJoin(this.route.value, ':uuid', ':options?'), controllers.preview);
}
_prepareContext(req, res, next) {
res.routerOptions = {
type: 'entry'
};
next();
}
}
module.exports = PreviewRouter;