From 143ba85be6a6f59b788ee180a74e492fc429c1d8 Mon Sep 17 00:00:00 2001 From: dekzter Date: Thu, 6 Mar 2025 12:02:57 -0500 Subject: [PATCH] support wss for websockets --- frontend/src/WebSocket.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/src/WebSocket.js b/frontend/src/WebSocket.js index a1fa1aaa..b121e7d8 100644 --- a/frontend/src/WebSocket.js +++ b/frontend/src/WebSocket.js @@ -19,9 +19,15 @@ export const WebsocketProvider = ({ children }) => { const ws = useRef(null); useEffect(() => { - let wsUrl = `ws://${window.location.host}/ws/`; + let wsUrl = `${window.location.host}/ws/`; if (process.env.REACT_APP_ENV_MODE == 'dev') { - wsUrl = `ws://${window.location.hostname}:8001/ws/`; + wsUrl = `${window.location.hostname}:8001/ws/`; + } + + if (window.location.protocol.match(/https/)) { + wsUrl = `wss://${wsUrl}`; + } else { + wsUrl = `ws://${wsUrl}`; } const socket = new WebSocket(wsUrl);