From ef987f54b059e46803b7c95d443363c79a82dcc2 Mon Sep 17 00:00:00 2001 From: iDefineHD Date: Sun, 11 Jan 2026 02:54:27 +0000 Subject: [PATCH] fixed routes --- frontend/src/utils/axios.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/frontend/src/utils/axios.js b/frontend/src/utils/axios.js index 3805e85..cef9eec 100644 --- a/frontend/src/utils/axios.js +++ b/frontend/src/utils/axios.js @@ -2,9 +2,37 @@ import axios from "axios"; import { useAuthStore } from "@/stores/auth"; import { useToast } from "vue-toastification"; +// Get the API base URL +const getApiBaseUrl = () => { + // If VITE_API_URL is set, use it + if (import.meta.env.VITE_API_URL) { + return import.meta.env.VITE_API_URL; + } + + // In production, use the api subdomain + if (import.meta.env.PROD) { + const currentHost = window.location.hostname; + const protocol = window.location.protocol; + + // If on turbotrades.dev, use api.turbotrades.dev + if ( + currentHost === "turbotrades.dev" || + currentHost === "www.turbotrades.dev" + ) { + return `${protocol}//api.turbotrades.dev/api`; + } + + // For other domains, try api subdomain + return `${protocol}//api.${currentHost}/api`; + } + + // In development, use relative path (Vite proxy handles it) + return "/api"; +}; + // Create axios instance const axiosInstance = axios.create({ - baseURL: import.meta.env.VITE_API_URL || "/api", + baseURL: getApiBaseUrl(), timeout: 15000, withCredentials: true, headers: {