// src/services/api.ts import axios from 'axios'; // Get API URL from environment variable or use relative path for production const getApiBaseUrl = () => { // Check for Vite environment variable first if (import.meta.env.VITE_API_URL) { return `${import.meta.env.VITE_API_URL}/api`; } // In production, use relative path to work with any domain if (import.meta.env.PROD) { return '/api'; } // Development fallback return 'http://localhost:8000/api'; }; const apiClient = axios.create({ baseURL: getApiBaseUrl(), headers: { 'Content-Type': 'application/json', }, }); export interface Domain { domain_id: string; name: string; description?: string; } export const fetchDomains = async (): Promise => { const response = await apiClient.get('/domains'); return response.data; }; export const fetchDomain = async (domainId: string): Promise => { const response = await apiClient.get(`/domains/${domainId}`); return response.data; }; export const updateDomain = async (domainId: string, data: Partial): Promise => { const response = await apiClient.put(`/domains/${domainId}`, data); return response.data; }; // You can add interceptors here if you need to handle tokens, etc. export default apiClient;