Merge pull request #161 from ets-cfuhrman-pfe/ssl-changes

Change the way the back-end url is set to a socket url
This commit is contained in:
Christopher (Cris) Fuhrman 2024-10-31 01:03:54 -04:00 committed by GitHub
commit c754d71623
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 9 additions and 7 deletions

2
.gitignore vendored
View file

@ -73,7 +73,7 @@ web_modules/
.yarn-integrity .yarn-integrity
# dotenv environment variable files # dotenv environment variable files
.env server/.env
.env.development.local .env.development.local
.env.test.local .env.test.local
.env.production.local .env.production.local

View file

@ -1,2 +1 @@
**/node_modules **/node_modules
.env

2
client/.env Normal file
View file

@ -0,0 +1,2 @@
VITE_BACKEND_URL=http://localhost:4400
VITE_AZURE_BACKEND_URL=http://localhost:4400

View file

@ -1,7 +1,7 @@
// constants.tsx // constants.tsx
const ENV_VARIABLES = { const ENV_VARIABLES = {
MODE: 'production', 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}`); console.log(`ENV_VARIABLES.VITE_BACKEND_URL=${ENV_VARIABLES.VITE_BACKEND_URL}`);

View file

@ -23,9 +23,10 @@ class WebSocketService {
connect(backendUrl: string): Socket { connect(backendUrl: string): Socket {
console.log(`WebSocketService.connect(${backendUrl})`); console.log(`WebSocketService.connect(${backendUrl})`);
// Ensure the URL uses wss: if the page is loaded over https: // Ensure the URL uses wss: if the URL starts with https:
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; const protocol = backendUrl.startsWith('https:') ? 'wss:' : 'ws:';
const url = backendUrl.replace(/^http:/, protocol); console.log(`WebSocketService.connect: protocol=${protocol}`);
const url = backendUrl.replace(/^http(s):/, protocol);
console.log(`WebSocketService.connect: changed url=${url}`); console.log(`WebSocketService.connect: changed url=${url}`);
this.socket = io(url, { this.socket = io(url, {

View file

@ -3,7 +3,7 @@
"target": "ESNext", "target": "ESNext",
"useDefineForClassFields": true, "useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"], "lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ES2020", "module": "ESNext",
"skipLibCheck": true, "skipLibCheck": true,
/* Bundler mode */ /* Bundler mode */