mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 16:01:40 +03:00
3d8bf02a8d
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()`
27 lines
769 B
JavaScript
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);
|
|
}
|
|
};
|