Actualizar frontend/src/lib/api.js
This commit is contained in:
@@ -1,5 +1,23 @@
|
|||||||
// Cliente del backend FastAPI de Leads (puerto 8001).
|
// Cliente del backend FastAPI de Leads.
|
||||||
const BASE_URL = import.meta.env.VITE_API_URL || "https://dashboardapi-leads.escueladerefrigeracion.lat";
|
// 1) Si existe VITE_API_URL (archivo .env del frontend), se usa esa.
|
||||||
|
// 2) Si no, se decide por el host desde el que se abrió la página:
|
||||||
|
// localhost -> backend local http://localhost:8001
|
||||||
|
// cualquier otro -> API publicada del servidor
|
||||||
|
const API_LOCAL = "http://localhost:8001";
|
||||||
|
const API_SERVIDOR = "https://api-leads.escueladerefrigeracion.lat";
|
||||||
|
|
||||||
|
function _baseUrlPorDefecto() {
|
||||||
|
if (typeof window === "undefined") return API_LOCAL;
|
||||||
|
const h = window.location.hostname;
|
||||||
|
return h === "localhost" || h === "127.0.0.1" || h === "::1"
|
||||||
|
? API_LOCAL
|
||||||
|
: API_SERVIDOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
const BASE_URL = (
|
||||||
|
import.meta.env.VITE_API_URL || _baseUrlPorDefecto()
|
||||||
|
).replace(/\/+$/, "");
|
||||||
|
|
||||||
// ── Cache en memoria (frontend) con TTL 15 min y "stale-while-revalidate" ──
|
// ── Cache en memoria (frontend) con TTL 15 min y "stale-while-revalidate" ──
|
||||||
// Guarda la respuesta de cada GET (por path+params). Al volver a pedir:
|
// Guarda la respuesta de cada GET (por path+params). Al volver a pedir:
|
||||||
// - si hay dato vigente (< 15 min) -> lo devuelve al instante, SIN fetch.
|
// - si hay dato vigente (< 15 min) -> lo devuelve al instante, SIN fetch.
|
||||||
@@ -196,4 +214,4 @@ export const api = {
|
|||||||
borrarCampania: (id) =>
|
borrarCampania: (id) =>
|
||||||
post("/api/campanias/borrar", { id },
|
post("/api/campanias/borrar", { id },
|
||||||
["/api/campanias", "/api/leads", "/api/vendedores", "/api/roas", "/api/otros-general", "/api/programa"]),
|
["/api/campanias", "/api/leads", "/api/vendedores", "/api/roas", "/api/otros-general", "/api/programa"]),
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user