Browse Source

Support passing through query params

Alasdair Smith 8 years ago
parent
commit
7e358ab318

+ 8 - 1
services/web/app/coffee/infrastructure/RedirectManager.coffee

@@ -23,4 +23,11 @@ module.exports = RedirectManager =
 					url = target.url
 				if target.baseUrl?
 					url = "#{target.baseUrl}#{url}"
-			res.redirect code, url
+			res.redirect code, url + getQueryString(req)
+
+# Naively get the query params string. Stringifying the req.query object may
+# have differences between Express and Rails, so safer to just pass the raw
+# string
+getQueryString = (req) ->
+	qs = req.url.match(/\?.*$/)
+	if qs? then qs[0] else ""

+ 3 - 0
services/web/test/acceptance/coffee/RedirectUrlsTests.coffee

@@ -29,3 +29,6 @@ describe "RedirectUrls", ->
 
 	it 'proxy URLs with multiple support methods', (done) ->
 		assertRedirect 'get', '/redirect/get_and_post', 302, '/destination/get_and_post', done
+
+	it 'redirects with query params', (done) ->
+		assertRedirect 'get', '/redirect/qs?foo=bar&baz[]=qux1&baz[]=qux2', 302, '/destination/qs?foo=bar&baz[]=qux1&baz[]=qux2', done

+ 2 - 1
services/web/test/acceptance/config/settings.test.coffee

@@ -125,4 +125,5 @@ module.exports =
 		},
 		'/redirect/params/:id': {
 			url: (params) -> "/destination/#{params.id}/params"
-		}
+		},
+		'/redirect/qs': '/destination/qs'