From fac82a96be98e1c7787e4db012342f0a11f4f944 Mon Sep 17 00:00:00 2001 From: Janis Date: Thu, 27 Nov 2025 07:51:02 +0100 Subject: [PATCH] fix(api): Fixed websocket routing (#88) Reviewed-on: https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/pulls/88 Co-authored-by: Janis Co-committed-by: Janis --- knockoutwhistweb/public/javascripts/websocket.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/knockoutwhistweb/public/javascripts/websocket.js b/knockoutwhistweb/public/javascripts/websocket.js index 7a32d71..fcd1c92 100644 --- a/knockoutwhistweb/public/javascripts/websocket.js +++ b/knockoutwhistweb/public/javascripts/websocket.js @@ -91,7 +91,12 @@ function setupSocketHandlers(socket) { } // connect/disconnect helpers -function connectWebSocket(url = "ws://localhost:9000/websocket") { +function connectWebSocket(url = null) { + if (!url) { + const loc = window.location; + const protocol = loc.protocol === "https:" ? "wss:" : "ws:"; + url = protocol + "//" + loc.host + "/websocket"; + } if (ws && ws.readyState === WebSocket.OPEN) return Promise.resolve(); if (ws && ws.readyState === WebSocket.CONNECTING) { // already connecting - return a promise that resolves on open