Skip to content

Commit 91f7889

Browse files
committed
fix (development): dynamic websocket protocol fix
1 parent 4fcf435 commit 91f7889

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/client/components/FloatingNav.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ export default function FloatingNav({ onChatOpen }) {
5454
const serverUrlHttp =
5555
process.env.NEXT_PUBLIC_APP_SERVER_URL ||
5656
"http://localhost:5000"
57-
const serverUrlWs = serverUrlHttp.replace(/^http/, "ws")
58-
const wsUrl = `${serverUrlWs}/api/ws/notifications`
57+
// Strip the protocol from the server URL to get just the host and port
58+
const serverHost = serverUrlHttp.replace(/^https?:\/\//, "")
59+
const wsUrl = `${wsProtocol}://${serverHost}/api/ws/notifications`
5960
const ws = new WebSocket(wsUrl)
6061
ws.isCleaningUp = false
6162
wsRef.current = ws

src/client/components/Sidebar.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ const Sidebar = ({ userDetails, setSidebarVisible, isSidebarVisible }) => {
6666
}
6767
const { accessToken } = await tokenResponse.json()
6868

69-
const wsProtocol =
70-
window.location.protocol === "https:" ? "wss" : "ws"
7169
const serverUrlHttp =
7270
process.env.NEXT_PUBLIC_APP_SERVER_URL ||
7371
"http://localhost:5000"
74-
const serverUrlWs = serverUrlHttp.replace(/^http/, "ws")
75-
const wsUrl = `${serverUrlWs}/api/ws/notifications`
72+
const wsProtocol =
73+
window.location.protocol === "https:" ? "wss" : "ws"
74+
// Strip the protocol from the server URL to get just the host and port
75+
const serverHost = serverUrlHttp.replace(/^https?:\/\//, "")
76+
const wsUrl = `${wsProtocol}://${serverHost}/api/ws/notifications`
7677

7778
const ws = new WebSocket(wsUrl)
7879
ws.isCleaningUp = false // Custom flag on the instance itself

0 commit comments

Comments
 (0)