From 0835a19c13ad419368424d44eb1d6087f5329fb1 Mon Sep 17 00:00:00 2001 From: Jonathan Rehm Date: Fri, 6 Dec 2019 16:00:34 -0700 Subject: [PATCH] feat(client): allow sock port to use location's port This change would allow the port to be specified by an individual proxy, e.g. if different team members have their environments configured differently --- client-src/default/utils/createSocketUrl.js | 6 +++++- test/client/utils/createSocketUrl.test.js | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/client-src/default/utils/createSocketUrl.js b/client-src/default/utils/createSocketUrl.js index d85f546159..058d714e08 100644 --- a/client-src/default/utils/createSocketUrl.js +++ b/client-src/default/utils/createSocketUrl.js @@ -76,7 +76,11 @@ function getSocketUrl(urlParts, loc) { // they are not provided const sockHost = query.sockHost || hostname; const sockPath = query.sockPath || '/sockjs-node'; - const sockPort = query.sockPort || port; + let sockPort = query.sockPort || port; + + if (sockPort === 'location') { + sockPort = loc.port; + } return url.format({ protocol, diff --git a/test/client/utils/createSocketUrl.test.js b/test/client/utils/createSocketUrl.test.js index a9ebfb8888..ab42ac67d7 100644 --- a/test/client/utils/createSocketUrl.test.js +++ b/test/client/utils/createSocketUrl.test.js @@ -141,6 +141,16 @@ describe('createSocketUrl', () => { 'http://localhost', 'http://localhost:8097/sockjs-node', ], + [ + '?http://example.com:8096&sockPort=location', + 'http://something.com', + 'http://example.com/sockjs-node', + ], + [ + '?http://0.0.0.0:8096&sockPort=location', + 'http://localhost:3000', + 'http://localhost:3000/sockjs-node', + ], ]; samples3.forEach(([scriptSrc, loc, expected]) => { test(`should return socket ${expected} for query ${scriptSrc} and location ${loc}`, () => {