refactor: API_BASE always uses same-origin /api (nginx proxy handles routing)
This commit is contained in:
1 parent
55b4dd52ff
commit
13c1712695
1 file changed
+4
-11
+4
-11
@@ -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}`;
|
||||
|
||||
Reference in new issue
Block a user