Skip to content

Commit 136cf54

Browse files
committed
feat(client): allow sock host to use browser location's host
This is templated off of commit 0835a19/#2341, but for the browser location's hostname instead of its port. Useful when webpack-dev-server is being accessed behind a reverse proxy.
1 parent 4ab1f21 commit 136cf54

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

client-src/default/utils/createSocketUrl.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,13 @@ function getSocketUrl(urlParts, loc) {
7474
// all of these sock url params are optionally passed in through
7575
// resourceQuery, so we need to fall back to the default if
7676
// they are not provided
77-
const sockHost = query.sockHost || hostname;
77+
let sockHost = query.sockHost || hostname;
7878
const sockPath = query.sockPath || '/sockjs-node';
7979
let sockPort = query.sockPort || port;
8080

81+
if (sockHost === 'location') {
82+
sockHost = loc.hostname;
83+
}
8184
if (sockPort === 'location') {
8285
sockPort = loc.port;
8386
}

test/client/utils/createSocketUrl.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ describe('createSocketUrl', () => {
126126
'http://something.com',
127127
'https://asdf/sockjs-node',
128128
],
129+
[
130+
'?http://example.com:8096&sockHost=location',
131+
'http://something.com',
132+
'http://something.com:8096/sockjs-node',
133+
],
134+
[
135+
'?http://0.0.0.0:8096&sockHost=location',
136+
'http://something.com',
137+
'http://something.com:8096/sockjs-node',
138+
],
129139
[
130140
'?https://example.com?sockPort=34',
131141
'http://something.com',
@@ -151,6 +161,11 @@ describe('createSocketUrl', () => {
151161
'http://localhost:3000',
152162
'http://localhost:3000/sockjs-node',
153163
],
164+
[
165+
'?http://example.com:8096&sockHost=location&sockPort=location',
166+
'http://something.com:3000',
167+
'http://something.com:3000/sockjs-node',
168+
],
154169
];
155170
samples3.forEach(([scriptSrc, loc, expected]) => {
156171
test(`should return socket ${expected} for query ${scriptSrc} and location ${loc}`, () => {

0 commit comments

Comments
 (0)