mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 21:33:24 +03:00
🐛 Fixed infinite redirect for amp when disabled
fixes 10883 - fixed an issue where /amp/ pages would cause an infinite redirect loop - this only occurred when amp was disabled, and query params were passed to the /amp/ url - this fix resolves the issue by not assuming /amp/ is the end of the URL - it also checks for `/amp/` (both slashes) and replaces one
This commit is contained in:
parent
bc8f8979c1
commit
ce563179b8
@ -1,16 +1,17 @@
|
||||
const router = require('./lib/router'),
|
||||
registerHelpers = require('./lib/helpers'),
|
||||
urlUtils = require('../../../server/lib/url-utils'),
|
||||
const router = require('./lib/router');
|
||||
const registerHelpers = require('./lib/helpers');
|
||||
const urlUtils = require('../../../server/lib/url-utils');
|
||||
|
||||
// Dirty requires
|
||||
settingsCache = require('../../../server/services/settings/cache');
|
||||
// Dirty requires
|
||||
const settingsCache = require('../../../server/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\/$/, '');
|
||||
let redirectUrl = req.originalUrl.replace(/\/amp\//, '/');
|
||||
|
||||
urlUtils.redirect301(res, redirectUrl);
|
||||
}
|
||||
}
|
||||
|
@ -262,6 +262,20 @@ describe('Frontend Routing', function () {
|
||||
.expect(301)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
it('should redirect to regular post with query params when AMP is disabled', function (done) {
|
||||
sinon.stub(settingsCache, 'get').callsFake(function (key, options) {
|
||||
if (key === 'amp' && !options) {
|
||||
return false;
|
||||
}
|
||||
return origCache.get(key, options);
|
||||
});
|
||||
|
||||
request.get('/welcome/amp/?q=a')
|
||||
.expect('Location', '/welcome/?q=a')
|
||||
.expect(301)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
});
|
||||
|
||||
describe('Static assets', function () {
|
||||
|
Loading…
Reference in New Issue
Block a user