refactor: API_BASE always uses same-origin /api (nginx proxy handles routing)

This commit is contained in:
Jorem Juárez committed 2026-04-21 11:26:53 -06:00
1 parent 55b4dd52ff
commit 13c1712695
1 file changed
+4 -11
+4 -11
View File
@@ -24,18 +24,11 @@ const COLORS = {
// ═══════════════════════════════════════════════════════════
// API CONFIG
// En producción el HTML vive bajo el mismo host que /api.
// En dev (localhost o file://) apunta a http://localhost:3001.
// El HTML siempre se sirve detrás de nginx (local: localhost:8080,
// prod: dominio del cliente). nginx hace proxy_pass de /api/ al servicio
// api interno, por eso basta con el mismo origen.
// ═══════════════════════════════════════════════════════════
const API_BASE = (() => {
if (window.location.protocol === "file:" || window.location.origin.includes("localhost")) {
return "http://localhost:3001/api";
}
return `${window.location.origin}/api`;
})();
// Debug — útil para validar que el origin/protocol se resuelven como esperamos
console.log("[wonderloo] origin:", window.location.origin, "protocol:", window.location.protocol, "API_BASE:", API_BASE);
const API_BASE = `${window.location.origin}/api`;
async function apiFetch(path, options = {}) {
const url = `${API_BASE}${path}`;