Files

24 lines
840 B
TypeScript

export function getApiUrl(path: string): string {
const cleanPath = path.startsWith('/') ? path : `/${path}`;
if (typeof window !== 'undefined' && window.location) {
const origin = window.location.origin;
// Local Expo dev server direct port
if (origin.includes(':8081')) {
return `http://localhost:8080/api${cleanPath}`;
}
// Deployed Modal Sandbox direct port
if (origin.includes('-8081.modal.run')) {
const backendOrigin = origin.replace('-8081.modal.run', '-8080.modal.run');
return `${backendOrigin}/api${cleanPath}`;
}
// Relative path works when accessed via port 5173 /mobile proxy
return `/api${cleanPath}`;
}
// Fallback for native devices
const baseUrl = process.env.EXPO_PUBLIC_API_URL || 'http://localhost:8080/api';
return `${baseUrl}${cleanPath}`;
}