| 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',
|
| },
|
| });
|
|
|
|
|
| api.interceptors.request.use(
|
| (config) => {
|
| console.log(`API Request: ${config.method.toUpperCase()} ${config.url}`);
|
| return config;
|
| },
|
| (error) => {
|
| return Promise.reject(error);
|
| }
|
| );
|
|
|
|
|
| api.interceptors.response.use(
|
| (response) => response,
|
| (error) => {
|
| console.error('API Error:', error.response?.data || error.message);
|
| return Promise.reject(error);
|
| }
|
| );
|
|
|
| export default api;
|
|
|
|
|
| export const endpoints = {
|
|
|
| plants: '/plants',
|
| plantById: (id) => `/plants/${id}`,
|
|
|
|
|
| surveys: '/surveys',
|
| surveyById: (id) => `/surveys/${id}`,
|
| surveyFull: (id) => `/surveys/${id}/full`,
|
|
|
|
|
| informants: '/informants',
|
|
|
|
|
| locations: '/locations',
|
|
|
|
|
| search: '/search',
|
| searchPlants: '/search/plants',
|
| searchCondition: '/search/condition',
|
|
|
|
|
| dashboard: '/stats/dashboard',
|
| plantStats: '/stats/plants',
|
| surveyStats: '/stats/surveys',
|
| locationStats: '/stats/by-location',
|
|
|
|
|
| health: '/health',
|
|
|
|
|
| media: '/media',
|
| mediaByType: (type) => `/media/type/${type}`,
|
| mediaByEntry: (entryId) => `/media/entry/${entryId}`,
|
| logoMedia: '/media/logo',
|
| homepageMedia: '/media/homepage',
|
| };
|
|
|