From be45db3eaa2a36a289bec754b873553096fac1f7 Mon Sep 17 00:00:00 2001 From: Claas Date: Wed, 19 Jun 2024 23:43:46 +0200 Subject: [PATCH] Require secure protocol outside of development --- client/src/context.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/client/src/context.tsx b/client/src/context.tsx index 407a769..362f83f 100644 --- a/client/src/context.tsx +++ b/client/src/context.tsx @@ -64,12 +64,17 @@ createEffect>((previous) => { return value; }, name()); +const isSecureRequired = + window.location.protocol === "https:" || + import.meta.env.MODE !== "development"; + export const backendUrl = new URL( - "http://" + (import.meta.env.VITE_DEV_BACKEND_HOST ?? window.location.host) + (isSecureRequired ? "https://" : "http://") + + (import.meta.env.VITE_DEV_BACKEND_HOST ?? window.location.host) ); console.debug("Backend at", backendUrl); const socketUrl = new URL(backendUrl.href); -socketUrl.protocol = "ws:"; +socketUrl.protocol = isSecureRequired ? "wss:" : "ws:"; // Use new socket if name changes createEffect((previous) => { -- 2.51.2