Ghost/core/server/apps/amp/index.js
Aileen Nowak 23f59c341c Replaced routeKeywords in config with hard coded keywords (#9561)
no issue
- removed the `routeKeywords` property from the config and used hard coded keywords.
- removed `routeKeywords` from public configuration API endpoint, as it's no longer used in the Admin.
2018-04-17 10:36:05 +01:00

28 lines
767 B
JavaScript

var router = require('./lib/router'),
registerHelpers = require('./lib/helpers'),
urlService = require('../../services/url'),
// Dirty requires
settingsCache = require('../../services/settings/cache');
function ampRouter(req, res) {
if (settingsCache.get('amp') === true) {
return router.apply(this, arguments);
} else {
// routeKeywords.amp: 'amp'
var redirectUrl = req.originalUrl.replace(/amp\/$/, '');
urlService.utils.redirect301(res, redirectUrl);
}
}
module.exports = {
activate: function activate(ghost) {
// routeKeywords.amp: 'amp'
var ampRoute = '*/amp/';
ghost.routeService.registerRouter(ampRoute, ampRouter);
registerHelpers(ghost);
}
};