Initial commit
This commit is contained in:
32
frontend/js/config.js
Normal file
32
frontend/js/config.js
Normal file
@@ -0,0 +1,32 @@
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user