From 77ccd486e9895f77eac0eb08c3493b7c63919632 Mon Sep 17 00:00:00 2001 From: Urtzi Alfaro Date: Sun, 3 Aug 2025 21:03:41 +0200 Subject: [PATCH] Fix new Frontend 5 --- docker-compose.yml | 2 -- frontend/src/api/client/index.ts | 32 +++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 4a48de04..9d74f267 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -591,13 +591,11 @@ services: dockerfile: Dockerfile.development # Use the existing development Dockerfile args: - NODE_ENV=development - - VITE_API_URL=http://localhost:${GATEWAY_PORT:-8000} image: bakery/dashboard:${IMAGE_TAG:-latest} container_name: bakery-dashboard restart: unless-stopped environment: - NODE_ENV=development - - VITE_API_URL=http://localhost:${GATEWAY_PORT:-8000} - VITE_APP_TITLE=PanIA Dashboard - VITE_APP_VERSION=1.0.0 ports: diff --git a/frontend/src/api/client/index.ts b/frontend/src/api/client/index.ts index 644bb67d..cf903a3c 100644 --- a/frontend/src/api/client/index.ts +++ b/frontend/src/api/client/index.ts @@ -25,8 +25,26 @@ export class ApiClient { private responseInterceptors: ResponseInterceptor[] = []; private metrics: RequestMetrics[] = []; - constructor(baseURL?: string) { - this.baseURL = baseURL || apiConfig.baseURL; +constructor(baseURL?: string) { + this.baseURL = baseURL || apiConfig.baseURL; + // ✅ CRITICAL FIX: Remove trailing slash + this.baseURL = this.baseURL.replace(/\/+$/, ''); + console.log('🔧 API Client initialized with baseURL:', this.baseURL); +} + +private buildURL(endpoint: string): string { + // Remove leading slash from endpoint if present to avoid double slashes + const cleanEndpoint = endpoint.startsWith('/') ? endpoint : `/${endpoint}`; + const fullURL = `${this.baseURL}${cleanEndpoint}`; + + // ✅ DEBUG: Log URL construction + console.log('🔗 Building URL:', { + baseURL: this.baseURL, + endpoint: cleanEndpoint, + fullURL: fullURL + }); + + return fullURL; } /** @@ -189,8 +207,15 @@ export class ApiClient { */ async request(endpoint: string, config: RequestConfig = {}): Promise { const startTime = Date.now(); - const url = `${this.baseURL}${endpoint}`; + const url = this.buildURL(endpoint); const method = config.method || 'GET'; + + console.log('🚀 Making API request:', { + method, + endpoint, + url, + config + }); // Apply request interceptors const modifiedConfig = await this.applyRequestInterceptors(config); @@ -486,4 +511,5 @@ export class ApiClient { } // Default API client instance +console.log('🔧 Creating default API client...'); export const apiClient = new ApiClient(); \ No newline at end of file