From 5411d29ca71e30b9aec4020fba721cb4d13a1065 Mon Sep 17 00:00:00 2001 From: iDefineHD Date: Sun, 11 Jan 2026 01:42:15 +0000 Subject: [PATCH] Fix WebSocket connection - use main API domain instead of ws subdomain - Updated WebSocket URL to use api.turbotrades.dev instead of ws.turbotrades.dev - Added frontend .env.production with correct VITE_WS_URL - Added frontend .env.development for local development - WebSocket now connects to wss://api.turbotrades.dev/ws --- frontend/.env.production | 16 ++++++++++++++++ frontend/src/stores/websocket.js | 9 ++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 frontend/.env.production diff --git a/frontend/.env.production b/frontend/.env.production new file mode 100644 index 0000000..9574844 --- /dev/null +++ b/frontend/.env.production @@ -0,0 +1,16 @@ +# Production Environment Variables for Frontend +# These are embedded at build time by Vite + +# API URL - Backend API endpoint +VITE_API_URL=https://api.turbotrades.dev + +# WebSocket URL - Backend WebSocket endpoint +# If not set, will auto-generate from VITE_API_URL +VITE_WS_URL=wss://api.turbotrades.dev/ws + +# App Configuration +VITE_APP_NAME=TurboTrades +VITE_APP_ENV=production + +# Feature Flags +VITE_ENABLE_DEBUG=false diff --git a/frontend/src/stores/websocket.js b/frontend/src/stores/websocket.js index bd5a069..7c353ef 100644 --- a/frontend/src/stores/websocket.js +++ b/frontend/src/stores/websocket.js @@ -31,14 +31,17 @@ export const useWebSocketStore = defineStore("websocket", () => { // Helper functions const getWebSocketUrl = () => { - // Use environment variable or fallback to ws subdomain + // Use environment variable or fallback if (import.meta.env.VITE_WS_URL) { return import.meta.env.VITE_WS_URL; } - // In production, use dedicated WebSocket domain + // In production, use main API domain with /ws path if (import.meta.env.PROD) { - return "wss://ws.turbotrades.dev"; + const apiUrl = + import.meta.env.VITE_API_URL || "https://api.turbotrades.dev"; + // Convert http(s):// to ws(s):// + return apiUrl.replace(/^http/, "ws") + "/ws"; } // In development, use current host with ws path (for proxy)