Skip to content

Commit

Permalink
feat(client): allow sock port to use location's port (#2341)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrehm authored and evilebottnawi committed Dec 9, 2019
1 parent a599f99 commit dc10d06
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion client-src/default/utils/createSocketUrl.js
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions test/client/utils/createSocketUrl.test.js
Expand Up @@ -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}`, () => {
Expand Down

0 comments on commit dc10d06

Please sign in to comment.