From e2c4e5cba29338d5f5d520c9ea8cf1c77ff551e4 Mon Sep 17 00:00:00 2001 From: "C. Fuhrman" Date: Thu, 31 Oct 2024 01:00:26 -0400 Subject: [PATCH] look at protocol in the env variable --- client/src/constants.tsx | 2 +- client/src/services/WebsocketService.tsx | 7 ++++--- client/tsconfig.json | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/client/src/constants.tsx b/client/src/constants.tsx index 032e68e..21ff020 100644 --- a/client/src/constants.tsx +++ b/client/src/constants.tsx @@ -1,7 +1,7 @@ // constants.tsx const ENV_VARIABLES = { MODE: 'production', - VITE_BACKEND_URL: import.meta.env.VITE_BACKEND_URL || "" + VITE_BACKEND_URL: process.env.VITE_BACKEND_URL || "" }; console.log(`ENV_VARIABLES.VITE_BACKEND_URL=${ENV_VARIABLES.VITE_BACKEND_URL}`); diff --git a/client/src/services/WebsocketService.tsx b/client/src/services/WebsocketService.tsx index 1ee91fb..8ba0da2 100644 --- a/client/src/services/WebsocketService.tsx +++ b/client/src/services/WebsocketService.tsx @@ -23,9 +23,10 @@ class WebSocketService { connect(backendUrl: string): Socket { console.log(`WebSocketService.connect(${backendUrl})`); - // Ensure the URL uses wss: if the page is loaded over https: - const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; - const url = backendUrl.replace(/^http:/, protocol); + // Ensure the URL uses wss: if the URL starts with https: + const protocol = backendUrl.startsWith('https:') ? 'wss:' : 'ws:'; + console.log(`WebSocketService.connect: protocol=${protocol}`); + const url = backendUrl.replace(/^http(s):/, protocol); console.log(`WebSocketService.connect: changed url=${url}`); this.socket = io(url, { diff --git a/client/tsconfig.json b/client/tsconfig.json index c9c40d8..5324e80 100644 --- a/client/tsconfig.json +++ b/client/tsconfig.json @@ -3,7 +3,7 @@ "target": "ESNext", "useDefineForClassFields": true, "lib": ["ES2020", "DOM", "DOM.Iterable"], - "module": "ES2020", + "module": "ESNext", "skipLibCheck": true, /* Bundler mode */