0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00
ghost/core/server/services/routing/StaticPagesRouter.js
Katharina Irrgang 6448c7bdc8
Fixed site using API v2 (#10332)
no issue

- See explanation: ef98c65040 (r31840536)
- that should not break anything, because resource consumption is based on resource type
- the alias pattern was only invented to make v2 work, it was a little dirty. i wanted to refactor that out anyway
2019-01-04 18:24:00 +01:00

61 lines
1.4 KiB
JavaScript

const debug = require('ghost-ignition').debug('services:routing:static-pages-router');
const ParentRouter = require('./ParentRouter');
const controllers = require('./controllers');
const common = require('../../lib/common');
class StaticPagesRouter extends ParentRouter {
constructor() {
super('StaticPagesRouter');
this.permalinks = {
value: '/:slug/'
};
this.permalinks.getValue = () => {
return this.permalinks.value;
};
debug(this.permalinks);
this._registerRoutes();
}
_registerRoutes() {
this.router().use(this._prepareContext.bind(this));
this.router().param('slug', this._respectDominantRouter.bind(this));
// REGISTER: permalink for static pages
this.mountRoute(this.permalinks.getValue(), controllers.entry);
common.events.emit('router.created', this);
}
_prepareContext(req, res, next) {
res.routerOptions = {
type: 'entry',
filter: this.filter,
permalinks: this.permalinks.getValue(),
resourceType: this.getResourceType(),
query: {
alias: 'pages',
resource: 'posts'
},
context: ['page']
};
next();
}
getResourceType() {
return 'pages';
}
getRoute() {
return null;
}
reset() {}
}
module.exports = StaticPagesRouter;