Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(client): allow sock host to use browser location's host #2859

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion client-src/default/utils/createSocketUrl.js
Expand Up @@ -74,10 +74,13 @@ function getSocketUrl(urlParts, loc) {
// all of these sock url params are optionally passed in through
// resourceQuery, so we need to fall back to the default if
// they are not provided
const sockHost = query.sockHost || hostname;
let sockHost = query.sockHost || hostname;
const sockPath = query.sockPath || '/sockjs-node';
let sockPort = query.sockPort || port;

if (sockHost === 'location') {
sockHost = loc.hostname;
}
if (sockPort === 'location') {
sockPort = loc.port;
}
Expand Down
15 changes: 15 additions & 0 deletions test/client/utils/createSocketUrl.test.js
Expand Up @@ -126,6 +126,16 @@ describe('createSocketUrl', () => {
'http://something.com',
'https://asdf/sockjs-node',
],
[
'?http://example.com:8096&sockHost=location',
'http://something.com',
'http://something.com:8096/sockjs-node',
],
[
'?http://0.0.0.0:8096&sockHost=location',
'http://something.com',
'http://something.com:8096/sockjs-node',
],
[
'?https://example.com?sockPort=34',
'http://something.com',
Expand All @@ -151,6 +161,11 @@ describe('createSocketUrl', () => {
'http://localhost:3000',
'http://localhost:3000/sockjs-node',
],
[
'?http://example.com:8096&sockHost=location&sockPort=location',
'http://something.com:3000',
'http://something.com:3000/sockjs-node',
],
];
samples3.forEach(([scriptSrc, loc, expected]) => {
test(`should return socket ${expected} for query ${scriptSrc} and location ${loc}`, () => {
Expand Down