mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
closes #10773 - The refactoring is a substitute for `urlService.utils` used previously throughout the codebase and now extracted into the separate module in Ghost-SDK - Added url-utils stubbing utility for test suites - Some tests had to be refactored to avoid double mocks (when url's are being reset inside of rested 'describe' groups)
27 lines
750 B
JavaScript
27 lines
750 B
JavaScript
const router = require('./lib/router'),
|
|
registerHelpers = require('./lib/helpers'),
|
|
urlUtils = require('../../lib/url-utils'),
|
|
|
|
// 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'
|
|
let redirectUrl = req.originalUrl.replace(/amp\/$/, '');
|
|
urlUtils.redirect301(res, redirectUrl);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
activate: function activate(ghost) {
|
|
// routeKeywords.amp: 'amp'
|
|
let ampRoute = '*/amp/';
|
|
|
|
ghost.routeService.registerRouter(ampRoute, ampRouter);
|
|
|
|
registerHelpers(ghost);
|
|
}
|
|
};
|