Retry URL 1716
This commit is contained in:
@@ -2,6 +2,9 @@ import { useState, useEffect, useCallback } from 'react';
|
||||
import apiClient from '../api/apiClient';
|
||||
import { AxiosError } from 'axios';
|
||||
|
||||
// Definimos la URL de la API en un solo lugar y de forma explícita.
|
||||
const API_ROOT = 'https://widgets.eldia.com/api';
|
||||
|
||||
export function useApiData<T>(endpoint: string) {
|
||||
const [data, setData] = useState<T | null>(null);
|
||||
const [loading, setLoading] = useState<boolean>(true);
|
||||
@@ -11,9 +14,11 @@ export function useApiData<T>(endpoint: string) {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
// Anteponemos '/api' a cada endpoint solicitado.
|
||||
// Ejemplo: si el endpoint es '/mercados/granos', la URL final será '/api/mercados/granos'
|
||||
const response = await apiClient.get<T>(`/api${endpoint}`);
|
||||
// --- V CORRECCIÓN DEFINITIVA V ---
|
||||
// Construimos la URL completa y absoluta para la llamada.
|
||||
const fullUrl = `${API_ROOT}${endpoint}`;
|
||||
const response = await apiClient.get<T>(fullUrl);
|
||||
// --- ^ CORRECCIÓN DEFINITIVA ^ ---
|
||||
setData(response.data);
|
||||
} catch (err) {
|
||||
if (err instanceof AxiosError) {
|
||||
|
||||
Reference in New Issue
Block a user