From cacd68ebfb8d190f18f675b49b7b7957eef12290 Mon Sep 17 00:00:00 2001 From: "William D. Jones" Date: Sun, 11 Jan 2026 19:09:52 -0600 Subject: [PATCH] Updates to deployment. --- frontend/src/utils/constants.ts | 36 +++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/frontend/src/utils/constants.ts b/frontend/src/utils/constants.ts index 39ebdb4..7830c2b 100644 --- a/frontend/src/utils/constants.ts +++ b/frontend/src/utils/constants.ts @@ -1,5 +1,37 @@ -export const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:8000' -export const WS_URL = import.meta.env.VITE_WS_URL || 'ws://localhost:8000' +// Auto-detect API URL based on environment +const getApiUrl = () => { + // If explicitly set via env var, use that + if (import.meta.env.VITE_API_URL) { + return import.meta.env.VITE_API_URL + } + + // In production (not localhost), use the current origin + if (typeof window !== 'undefined' && !window.location.hostname.includes('localhost')) { + return window.location.origin + } + + // Default for local development + return 'http://localhost:8000' +} + +const getWsUrl = () => { + // If explicitly set via env var, use that + if (import.meta.env.VITE_WS_URL) { + return import.meta.env.VITE_WS_URL + } + + // In production (not localhost), use the current origin with ws/wss protocol + if (typeof window !== 'undefined' && !window.location.hostname.includes('localhost')) { + const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:' + return `${protocol}//${window.location.host}` + } + + // Default for local development + return 'ws://localhost:8000' +} + +export const API_URL = getApiUrl() +export const WS_URL = getWsUrl() export const BET_CATEGORIES = { sports: 'Sports',