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 */