From 68048dfd5620e22d21bb3172478d6300ab39164b Mon Sep 17 00:00:00 2001 From: nix Date: Thu, 30 Jan 2025 21:09:53 +0100 Subject: [PATCH] add websocket subpath support --- ui/components/ChatWindow.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ui/components/ChatWindow.tsx b/ui/components/ChatWindow.tsx index b26573f..d532d10 100644 --- a/ui/components/ChatWindow.tsx +++ b/ui/components/ChatWindow.tsx @@ -393,8 +393,17 @@ const ChatWindow = ({ id }: { id?: string }) => { const [isReady, setIsReady] = useState(false); const [isWSReady, setIsWSReady] = useState(false); + + let websocketUrl = process.env.NEXT_PUBLIC_WS_URL!; + if (websocketUrl.startsWith('/')) { + const protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://'; + const host = window.location.host; + const path = websocketUrl; + websocketUrl = `${protocol}${host}${path}`; + } + const ws = useSocket( - process.env.NEXT_PUBLIC_WS_URL!, + websocketUrl, setIsWSReady, setHasError, );