From 54efb85dc30cb39c2924ff5c3531c8acdcd5059b Mon Sep 17 00:00:00 2001 From: Lucas Schumacher Date: Wed, 1 Nov 2023 02:25:12 -0400 Subject: [PATCH] Use wss in test page when connected with https --- src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index dfcf743..ffc55a6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,7 +55,8 @@ fn index() -> Html<&'static str> { sendForm.hidden = false; msgsArea.hidden = false; msgInput.focus(); - ws = new WebSocket("ws://" + window.location.host + "/api/ws"); + let protocol = window.location.protocol == "https:" ? "wss://" : "ws://"; + ws = new WebSocket(protocol + window.location.host + "/api/ws"); ws.onmessage = function(event) { msgsArea.value += event.data + "\r\n"; }