look at protocol in the env variable

This commit is contained in:
C. Fuhrman 2024-10-31 01:00:26 -04:00
parent e113e2f9e9
commit e2c4e5cba2
3 changed files with 6 additions and 5 deletions

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