From 68048dfd5620e22d21bb3172478d6300ab39164b Mon Sep 17 00:00:00 2001 From: nix Date: Thu, 30 Jan 2025 21:09:53 +0100 Subject: [PATCH 1/2] 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, ); From 728919f7bfbcf906139e8ffd6c7f07a5a98d42c6 Mon Sep 17 00:00:00 2001 From: nix Date: Fri, 31 Jan 2025 20:09:58 +0100 Subject: [PATCH 2/2] formating --- ui/components/ChatWindow.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/ui/components/ChatWindow.tsx b/ui/components/ChatWindow.tsx index d532d10..4f85edc 100644 --- a/ui/components/ChatWindow.tsx +++ b/ui/components/ChatWindow.tsx @@ -402,11 +402,7 @@ const ChatWindow = ({ id }: { id?: string }) => { websocketUrl = `${protocol}${host}${path}`; } - const ws = useSocket( - websocketUrl, - setIsWSReady, - setHasError, - ); + const ws = useSocket(websocketUrl, setIsWSReady, setHasError); const [loading, setLoading] = useState(false); const [messageAppeared, setMessageAppeared] = useState(false);