Fix double /api prefix in fetchAccesses by using ENDPOINTS constant

fetchAccesses was passing the hardcoded absolute path /api/dashboard/accesses
to get(), which prepends BASE_URL (/api), producing /api/api/dashboard/accesses.
Added ENDPOINTS.dashboardAccesses and switched to use it, consistent with every
other function in dashboard.ts.
This commit is contained in:
2026-03-01 21:05:30 +01:00
parent 6e76711940
commit 401a5d4169
3 changed files with 10 additions and 12 deletions

View File

@@ -4,17 +4,14 @@ This document breaks the entire BanGUI project into development stages, ordered
---
## ✅ FIXED — Blocklist import: `No module named 'fail2ban'` on every IP (2026-03-01)
## ✅ FIXED — Access list 404: `/api/api/dashboard/accesses` double prefix (2026-03-01)
**Root cause:** In `app/main.py`, the `fail2ban-master` path was computed using
`Path(__file__).resolve().parents[2] / "fail2ban-master"`. This resolves correctly
in local dev (`backend/app/main.py` → repo root) but resolves to `/fail2ban-master`
inside the Docker container (where the source is copied to `/app/app/main.py`),
so `fail2ban` was never added to `sys.path` and `pickle.loads()` raised
`ModuleNotFoundError: No module named 'fail2ban'` for every socket response.
**Root cause:** `fetchAccesses` in `src/api/dashboard.ts` passed the hardcoded absolute path
`/api/dashboard/accesses` directly to `get()`. Because `get()` prepends `BASE_URL` (`/api`),
the resulting URL became `/api/api/dashboard/accesses`, which has no backend route.
**Fix:** Replaced the hardcoded `parents[2]` with a walk-up loop
(`_find_fail2ban_master()`) that iterates over all ancestors until it finds a
`fail2ban-master/` sibling directory — correct in both local dev and Docker.
**Fix:** Added `dashboardAccesses: "/dashboard/accesses"` to `ENDPOINTS` in `src/api/endpoints.ts`
and changed `fetchAccesses` to use `ENDPOINTS.dashboardAccesses` — consistent with every other
function in the same file.
**Commit:** `19bb94e` — _Fix fail2ban-master path resolution for Docker container_
**Commit:** _Fix double /api prefix in fetchAccesses by using ENDPOINTS constant_

View File

@@ -63,6 +63,6 @@ export async function fetchAccesses(
page: String(page),
page_size: String(pageSize),
});
return get<AccessListResponse>(`/api/dashboard/accesses?${params.toString()}`);
return get<AccessListResponse>(`${ENDPOINTS.dashboardAccesses}?${params.toString()}`);
}

View File

@@ -30,6 +30,7 @@ export const ENDPOINTS = {
dashboardStatus: "/dashboard/status",
dashboardBans: "/dashboard/bans",
dashboardBansByCountry: "/dashboard/bans/by-country",
dashboardAccesses: "/dashboard/accesses",
// -------------------------------------------------------------------------
// Jails