import axios from 'axios'; const API_BASE_URL = process.env.REACT_APP_API_URL || '/api'; const api = axios.create({ baseURL: API_BASE_URL, headers: { 'Content-Type': 'application/json', }, }); // Request interceptor for logging api.interceptors.request.use( (config) => { console.log(`API Request: ${config.method.toUpperCase()} ${config.url}`); return config; }, (error) => { return Promise.reject(error); } ); // Response interceptor for error handling api.interceptors.response.use( (response) => response, (error) => { console.error('API Error:', error.response?.data || error.message); return Promise.reject(error); } ); export default api; // API endpoints export const endpoints = { // Plants plants: '/plants', plantById: (id) => `/plants/${id}`, // Surveys surveys: '/surveys', surveyById: (id) => `/surveys/${id}`, surveyFull: (id) => `/surveys/${id}/full`, // Informants informants: '/informants', // Locations locations: '/locations', // Search search: '/search', searchPlants: '/search/plants', searchCondition: '/search/condition', // Statistics dashboard: '/stats/dashboard', plantStats: '/stats/plants', surveyStats: '/stats/surveys', locationStats: '/stats/by-location', // Health health: '/health', // Media media: '/media', mediaByType: (type) => `/media/type/${type}`, mediaByEntry: (entryId) => `/media/entry/${entryId}`, logoMedia: '/media/logo', homepageMedia: '/media/homepage', };