0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/core/server/services/routing/PreviewRouter.js
kirrg001 e302be2749 Changed preview controller to support v0.1 and v2
refs #9866

- invent preview api, but only used internally
  - the idea of a preview api is definitiely reaslistic and came up in the past a couple of times
- by that we don't have to differentiate between pages or posts controller
- still support v0.1
- preview controller is not registered for http, only internal handling
2018-10-18 19:41:07 +02:00

30 lines
710 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',
resourceType: 'preview'
};
next();
}
}
module.exports = PreviewRouter;