From af5b1ab4060ca10ebce6c5b1be80786a24594993 Mon Sep 17 00:00:00 2001 From: Alexander Borg Date: Mon, 18 Aug 2025 05:51:54 +0200 Subject: [PATCH] Fix jwt-token --- client/src/services/api.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/client/src/services/api.js b/client/src/services/api.js index 078009c..5944d7c 100644 --- a/client/src/services/api.js +++ b/client/src/services/api.js @@ -1,9 +1,24 @@ import axios from 'axios'; -const API_BASE_URL = import.meta.env.VITE_API_URL || - (process.env.NODE_ENV === 'production' - ? '/drones/api' - : 'http://localhost:3002/api'); +// Determine API base URL based on environment +const getApiBaseUrl = () => { + // If VITE_API_URL is explicitly set, use it + if (import.meta.env.VITE_API_URL) { + return import.meta.env.VITE_API_URL; + } + + // If we're on localhost, use localhost API + if (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') { + return 'http://localhost:3002/api'; + } + + // Otherwise, use relative URL (same domain) + return '/drones/api'; +}; + +const API_BASE_URL = getApiBaseUrl(); + +console.log('🔗 API Base URL:', API_BASE_URL); const api = axios.create({ baseURL: API_BASE_URL,