minor bug fixes
This commit is contained in:
parent
82edc313f4
commit
d49478ff18
3 changed files with 45 additions and 5 deletions
2
.env
2
.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"
|
||||
|
|
|
|||
|
|
@ -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/"
|
||||
|
|
|
|||
44
src/api.ts
44
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<string | null> => {
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue