From 327875dceb5f5e72a6120e19a3dbabb7f55554fd Mon Sep 17 00:00:00 2001 From: "C. Fuhrman" Date: Wed, 30 Oct 2024 23:58:56 -0400 Subject: [PATCH 1/2] make sure backend env is set for client --- .gitignore | 2 +- client/.dockerignore | 1 - client/.env | 2 ++ 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 client/.env diff --git a/.gitignore b/.gitignore index ae7f632..6e8de7b 100644 --- a/.gitignore +++ b/.gitignore @@ -73,7 +73,7 @@ web_modules/ .yarn-integrity # dotenv environment variable files -.env +server/.env .env.development.local .env.test.local .env.production.local diff --git a/client/.dockerignore b/client/.dockerignore index fb664ef..cf70988 100644 --- a/client/.dockerignore +++ b/client/.dockerignore @@ -1,2 +1 @@ **/node_modules -.env \ No newline at end of file diff --git a/client/.env b/client/.env new file mode 100644 index 0000000..fa03bbb --- /dev/null +++ b/client/.env @@ -0,0 +1,2 @@ +VITE_BACKEND_URL=http://localhost:4400 +VITE_AZURE_BACKEND_URL=http://localhost:4400 From e2c4e5cba29338d5f5d520c9ea8cf1c77ff551e4 Mon Sep 17 00:00:00 2001 From: "C. Fuhrman" Date: Thu, 31 Oct 2024 01:00:26 -0400 Subject: [PATCH 2/2] 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 */