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}`, () => {