CoolFace
Apppublic

DataScope26/WEB

sourceHugging Faceupdated 7d agoView on Hugging Face
0likes
axiosClient.js40 linesDownload Raw Back to services
1import axios from "axios";2 3// Obtiene la URL del .env o usa la de pruebas como fallback para desarrollo local4const rawApiUrl = import.meta.env.API_URL || "https://erulman-api-pruebas.hf.space";5import { getCookie, deleteCookie } from "../utils/cookieUtils.js"6 7 8const axiosClient = axios.create({9  baseURL: `${rawApiUrl}/api`,10});11 12//baseURL: "https://datascope26-api.hf.space/api"13//Pruebas: "https://erulman-api-pruebas.hf.space/api"14//Local: "http://localhost:7860/api"15//Nube: ${rawApiUrl}/api + agregar .env --> import.meta.env.API_URL => "https://erulman-api-pruebas.hf.space"16 17axiosClient.interceptors.response.use(18  response => response,19  error => {20 21    if (22      error.response?.status === 401 &&23      error.response?.data === "Token expired."24    ) {25 26      localStorage.removeItem("token")27      sessionStorage.removeItem("token")28      const cookieExists = getCookie("datascope_token")29      if (cookieExists) deleteCookie("datascope_token")30        31      window.location.href = "/";32    }33 34    return Promise.reject(error);35  }36);37 38 39 40export default axiosClient;