33 lines
910 B
JavaScript
33 lines
910 B
JavaScript
// Configuración de la API
|
|
const API_CONFIG = {
|
|
BASE_URL: 'http://localhost:8000/api',
|
|
// En producción cambiar a: BASE_URL: 'https://tu-dominio.com/api'
|
|
};
|
|
|
|
// Función helper para hacer requests
|
|
async function apiRequest(endpoint, options = {}) {
|
|
const url = `${API_CONFIG.BASE_URL}${endpoint}`;
|
|
const defaultOptions = {
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
};
|
|
|
|
const config = { ...defaultOptions, ...options };
|
|
|
|
try {
|
|
const response = await fetch(url, config);
|
|
|
|
if (!response.ok) {
|
|
const error = await response.json().catch(() => ({ detail: 'Error desconocido' }));
|
|
throw new Error(error.detail || `Error ${response.status}`);
|
|
}
|
|
|
|
return await response.json();
|
|
} catch (error) {
|
|
console.error('API Error:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
|