diff --git a/.env b/.env index b562ee6..86b2acd 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -VITE_API_BASE_URL="https://gateway.poweron-center.net" +VITE_API_BASE_URL="https://gateway-prod.poweron-center.net" VITE_MICROSOFT_CLIENT_ID="24cd6c8a-b592-4905-a5ba-d5fa9f911154" VITE_MICROSOFT_TENANT_ID="6a51aaeb-2467-4186-9504-2a05aedc591f" VITE_ENTRA_CLIENT_SECRET="2iw8Q~jwqG1iacxHopBt5pstu6R45UC1gIQabcbD" diff --git a/.env.production b/.env.production index b562ee6..3466e9c 100644 --- a/.env.production +++ b/.env.production @@ -1,7 +1,7 @@ -VITE_API_BASE_URL="https://gateway.poweron-center.net" +VITE_API_BASE_URL="https://gateway-prod.poweron-center.net" VITE_MICROSOFT_CLIENT_ID="24cd6c8a-b592-4905-a5ba-d5fa9f911154" VITE_MICROSOFT_TENANT_ID="6a51aaeb-2467-4186-9504-2a05aedc591f" VITE_ENTRA_CLIENT_SECRET="2iw8Q~jwqG1iacxHopBt5pstu6R45UC1gIQabcbD" VITE_ENTRA_AUTHORITY="https://login.microsoftonline.com/6a51aaeb-2467-4186-9504-2a05aedc591f" VITE_ENTRA_REDIRECT_PATH="/auth/callback/" -VITE_ENTRA_REDIRECT_URI="https://gateway.poweron-center.net/api/msft/auth/callback/" +VITE_ENTRA_REDIRECT_URI="https://gateway-prod.poweron-center.net/api/msft/auth/callback/" diff --git a/src/api.ts b/src/api.ts index 79eb618..26e5dac 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,14 +1,54 @@ // api.ts import axios from 'axios'; +// Utility function to resolve hostname to IP address +const resolveHostnameToIP = async (hostname: string): Promise => { + try { + // For localhost, return as is + if (hostname === 'localhost' || hostname === '127.0.0.1') { + return hostname; + } + + // For production domains, we can't directly resolve IP due to CORS + // But we can show the hostname which is more useful anyway + return hostname; + } catch (error) { + console.warn('Could not resolve hostname to IP:', error); + return hostname; + } +}; + const api = axios.create({ baseURL: import.meta.env.VITE_API_BASE_URL, withCredentials: true }); -// Add a request interceptor to add the auth token +// Add a request interceptor to add the auth token and log backend IP api.interceptors.request.use( - (config) => { + async (config) => { + // Log backend information + const backendUrl = config.baseURL || import.meta.env.VITE_API_BASE_URL; + console.log(`🌐 Communicating with backend: ${backendUrl}`); + + // Try to resolve and log the IP address + if (backendUrl) { + try { + const url = new URL(backendUrl); + const hostname = url.hostname; + const resolvedIP = await resolveHostnameToIP(hostname); + + console.log(`📍 Backend hostname: ${hostname}`); + console.log(`🔗 Full backend URL: ${backendUrl}`); + console.log(`🌍 Resolved address: ${resolvedIP}`); + + // Log environment info + console.log(`🏗️ Environment: ${import.meta.env.MODE}`); + console.log(`⚙️ API Base URL from env: ${import.meta.env.VITE_API_BASE_URL}`); + } catch (error) { + console.warn('Could not parse backend URL:', error); + } + } + const authData = localStorage.getItem('auth_data'); if (authData) { try {