Skip to content

Commit

Permalink
fix: support custom url protocol scheme on websockets (#1173)
Browse files Browse the repository at this point in the history
* fix: support custom url protocol scheme on websockets

* lint
  • Loading branch information
ilyaGurevich authored Feb 29, 2024
1 parent 2cbd7c9 commit 9d0dbf5
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions packages/kyt-core/src/config/webpackHotDevClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,31 @@ if (module.hot && typeof module.hot.dispose === 'function') {
});
}

// Connect to WebpackDevServer via a socket.
const connection = new SockJS(
url.format({
protocol: window.location.protocol,
hostname: window.location.hostname,
port: sockJSPort,
// Hardcoded in WebpackDevServer
pathname: '/sockjs-node',
})
);
let connection;
if (!window.location.protocol.includes('http')) {
// if the location protocol doesn't include http use a normal web-socket
// sockjs doesn't support custom protocols
connection = new WebSocket(
url.format({
protocol: 'wss',
hostname: window.location.hostname,
port: sockJSPort,
// Hardcoded in WebpackDevServer
pathname: '/sockjs-node',
})
);
} else {
// Connect to WebpackDevServer via a socket.
connection = new SockJS(
url.format({
protocol: window.location.protocol,
hostname: window.location.hostname,
port: sockJSPort,
// Hardcoded in WebpackDevServer
pathname: '/sockjs-node',
})
);
}

// Unlike WebpackDevServer client, we won't try to reconnect
// to avoid spamming the console. Disconnect usually happens
Expand Down

0 comments on commit 9d0dbf5

Please sign in to comment.