From 9d0dbf5971ad85d0770b6ebf676459d53b287fcf Mon Sep 17 00:00:00 2001 From: Ilya Gurevich Date: Thu, 29 Feb 2024 14:13:23 -0500 Subject: [PATCH] fix: support custom url protocol scheme on websockets (#1173) * fix: support custom url protocol scheme on websockets * lint --- .../src/config/webpackHotDevClient.js | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/packages/kyt-core/src/config/webpackHotDevClient.js b/packages/kyt-core/src/config/webpackHotDevClient.js index 6424d06f2..ae6e83aff 100644 --- a/packages/kyt-core/src/config/webpackHotDevClient.js +++ b/packages/kyt-core/src/config/webpackHotDevClient.js @@ -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