mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-24 22:14:08 +00:00
Support the same URL with multiple methods in redirects
This commit is contained in:
parent
83a1039b7e
commit
15103ac894
3 changed files with 14 additions and 8 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue