Ghost/core/server/apps/amp/index.js
Rosco Kalis 3d8bf02a8d Redirected /amp links to original post when AMP is disabled (#9496)
closes #9495

- Added a clause for amp being disabled
- In this clause, we strip the final 'amp/' part of the url, and redirect
- Changed corresponding test in frontend_spec.js
- Used `urlService.utils.redirect301()` instead of `res.redirect()`
2018-03-19 16:11:48 +07:00

27 lines
769 B
JavaScript

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