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
Katharina Irrgang 6b758bda79
Refactored routing config for multiple api versions (#10333)
refs #10124

- one clean v0.1 and v2 config file for routing!
- solves one underlying bug reported in #10124
- the alias handling was just a hotfix to support v2 for the site
- but it was hard to read, ugly
- now we have two clean configs
- we'll see how useful it is
- need to do proper manual testing on Monday
2019-01-04 21:59:39 +01:00

32 lines
792 B
JavaScript

const ParentRouter = require('./ParentRouter');
const urlService = require('../url');
const controllers = require('./controllers');
class PreviewRouter extends ParentRouter {
constructor(RESOURCE_CONFIG) {
super('PreviewRouter');
this.RESOURCE_CONFIG = RESOURCE_CONFIG.QUERY.preview;
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',
query: this.RESOURCE_CONFIG
};
next();
}
}
module.exports = PreviewRouter;