feat(seguridad): rutas admin bajo prefijo configurable obligatorio
deploy-branch / deploy (push) Failing after 3m7s
deploy-branch / teardown (push) Skipped
tests / Unitarias + componente + build (push) Failing after 3m17s
tests / Integración (Nominatim real, opt-in) (push) Skipped
tests / Unitarias + componente + build (pull_request) Failing after 3m10s
tests / Integración (Nominatim real, opt-in) (pull_request) Skipped
deploy-branch / deploy (push) Failing after 3m7s
deploy-branch / teardown (push) Skipped
tests / Unitarias + componente + build (push) Failing after 3m17s
tests / Integración (Nominatim real, opt-in) (push) Skipped
tests / Unitarias + componente + build (pull_request) Failing after 3m10s
tests / Integración (Nominatim real, opt-in) (pull_request) Skipped
Cambio openspec hide-admin-route: las rutas de administración se montan bajo LOCALESP_ADMIN_PREFIX (única variable, obligatoria, sin valor por defecto) y las rutas históricas /api/... dejan de existir (404 natural). - server: autocarga de .env (sin pisar el entorno) y fail-fast claro si falta LOCALESP_ADMIN_PREFIX; reportar/confirmar siguen públicas - frontend: src/api.js usa el prefijo expuesto por Vite (envPrefix); npm run build falla sin la variable; proxy de dev la lee vía loadEnv - .env.example como template único de configuración - tests: 109/109 en verde (rutas bajo prefijo, 404s históricos y fail-fast sin configurar) - openspec: artefactos del cambio sincronizados (design/spec/tasks)
This commit is contained in:
+13
-7
@@ -1,6 +1,12 @@
|
||||
// Local SQLite API instead of Firebase
|
||||
|
||||
const API_URL = "/api";
|
||||
// Prefijo de las rutas de administración: la MISMA variable que usa el
|
||||
// servidor (LOCALESP_ADMIN_PREFIX), expuesta al frontend por Vite mediante
|
||||
// `envPrefix` (dev/build la recogen de .env o del entorno; el build falla si
|
||||
// falta). El fallback "/api" solo aplica fuera de un build real (p. ej. tests).
|
||||
const rawAdmin = String(import.meta.env.LOCALESP_ADMIN_PREFIX || "").trim().replace(/\/+$/, "");
|
||||
const ADMIN_URL = rawAdmin ? (rawAdmin.startsWith("/") ? rawAdmin : `/${rawAdmin}`) : "/api";
|
||||
|
||||
export async function suscribirLocales(onData, onError) {
|
||||
try {
|
||||
@@ -25,13 +31,13 @@ export async function suscribirLocales(onData, onError) {
|
||||
|
||||
export async function suscribirPendientes(onData, onError) {
|
||||
try {
|
||||
const response = await fetch(`${API_URL}/pendientes`);
|
||||
const response = await fetch(`${ADMIN_URL}/pendientes`);
|
||||
const data = await response.json();
|
||||
onData(data);
|
||||
// Simulate real-time by polling every 5 seconds
|
||||
const interval = setInterval(async () => {
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/pendientes`);
|
||||
const res = await fetch(`${ADMIN_URL}/pendientes`);
|
||||
const newData = await res.json();
|
||||
onData(newData);
|
||||
} catch (err) {
|
||||
@@ -64,7 +70,7 @@ export async function comprobarDuplicado({ nombre, provincia, lat, lng }) {
|
||||
}
|
||||
|
||||
export async function aprobarPropuesta(p) {
|
||||
const response = await fetch(`${API_URL}/aprobar/${p.id}`, {
|
||||
const response = await fetch(`${ADMIN_URL}/aprobar/${p.id}`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
@@ -72,7 +78,7 @@ export async function aprobarPropuesta(p) {
|
||||
}
|
||||
|
||||
export async function rechazarPropuesta(id) {
|
||||
const response = await fetch(`${API_URL}/rechazar/${id}`, {
|
||||
const response = await fetch(`${ADMIN_URL}/rechazar/${id}`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
@@ -80,7 +86,7 @@ export async function rechazarPropuesta(id) {
|
||||
}
|
||||
|
||||
export async function deleteLocal(id) {
|
||||
const response = await fetch(`${API_URL}/locales/${id}`, {
|
||||
const response = await fetch(`${ADMIN_URL}/locales/${id}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
return response.json();
|
||||
@@ -101,12 +107,12 @@ export async function reportarLocal(id, motivo, comentario) {
|
||||
}
|
||||
|
||||
export async function obtenerReportes() {
|
||||
const response = await fetch(`${API_URL}/reportes`);
|
||||
const response = await fetch(`${ADMIN_URL}/reportes`);
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export async function descartarReporte(id) {
|
||||
const response = await fetch(`${API_URL}/reportes/${id}/descartar`, { method: "POST" });
|
||||
const response = await fetch(`${ADMIN_URL}/reportes/${id}/descartar`, { method: "POST" });
|
||||
return response.json();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user