diff --git a/services/web/app/coffee/infrastructure/RedirectManager.coffee b/services/web/app/coffee/infrastructure/RedirectManager.coffee index 7fac7ef1ec..2f9ffd1397 100644 --- a/services/web/app/coffee/infrastructure/RedirectManager.coffee +++ b/services/web/app/coffee/infrastructure/RedirectManager.coffee @@ -4,8 +4,7 @@ logger = require("logger-sharelatex") module.exports = RedirectManager = apply: (webRouter) -> for redirectUrl, target of settings.redirects - do (target) -> - method = target.method || 'get' + for method in (target.methods or ['get']) webRouter[method] redirectUrl, RedirectManager.createRedirect(target) createRedirect: (target) -> @@ -14,7 +13,7 @@ module.exports = RedirectManager = if typeof target is 'string' url = target else - if target.method == "post" + if req.method == "POST" code = 307 if typeof target.url == "function" url = target.url(req.params) diff --git a/services/web/test/acceptance/coffee/RedirectUrlsTests.coffee b/services/web/test/acceptance/coffee/RedirectUrlsTests.coffee index 90c5a62b9b..f1c0f4e8dd 100644 --- a/services/web/test/acceptance/coffee/RedirectUrlsTests.coffee +++ b/services/web/test/acceptance/coffee/RedirectUrlsTests.coffee @@ -24,5 +24,8 @@ describe "RedirectUrls", -> it 'proxy URLs with baseUrl', (done) -> assertRedirect 'get', '/redirect/base_url', 302, 'https://example.com/destination/base_url', done - it 'proxy URLs with POST', (done) -> - assertRedirect 'post', '/redirect/post', 307, '/destination/post', done + it 'proxy URLs with POST with a 307', (done) -> + assertRedirect 'post', '/redirect/get_and_post', 307, '/destination/get_and_post', done + + it 'proxy URLs with multiple support methods', (done) -> + assertRedirect 'get', '/redirect/get_and_post', 302, '/destination/get_and_post', done diff --git a/services/web/test/acceptance/config/settings.test.coffee b/services/web/test/acceptance/config/settings.test.coffee index 400d24d016..521b44cbb6 100644 --- a/services/web/test/acceptance/config/settings.test.coffee +++ b/services/web/test/acceptance/config/settings.test.coffee @@ -105,15 +105,19 @@ module.exports = path: (params) -> "/universities/list/#{params.id}" '/institutions/domains': { baseUrl: v1Api.url, path: '/university/domains' } '/proxy/missing/baseUrl': path: '/foo/bar' + '/proxy/get_and_post': { + methods: ['get', 'post'], + path: '/destination/get_and_post' + } overleaf: host: "http://overleaf.test:5000" redirects: '/redirect/one': '/destination/one', - '/redirect/post': { - method: 'post', - url: '/destination/post' + '/redirect/get_and_post': { + methods: ['get', 'post'], + url: '/destination/get_and_post' }, '/redirect/base_url': { baseUrl: 'https://example.com'