fix(mount): strip doubled router prefixes from 452 routes (98%)

Routes had both router.prefix and route.path containing the same
prefix, producing /api/v1/scanner/api/v1/scanner/scan instead of
/api/v1/scanner/scan. Mount now detects and strips the overlap,
then restores the prefix for bookkeeping.
This commit is contained in:
Crypto Rug Munch 2026-07-08 07:07:01 +02:00
parent b454e9c3f7
commit 4712ec80ec

View file

@ -127,7 +127,18 @@ def _try_mount(app: Any, module_path: str) -> bool:
if router is None:
log.warning("router_missing path=%s (no `router` attribute)", module_path)
return False
# Fix doubled prefixes: if the router prefix is duplicated
# in route paths (e.g. router.prefix="/api/v1/scanner" and
# route.path="/api/v1/scanner/scan"), strip the router prefix
# so the effective URL is clean.
rprefix = getattr(router, "prefix", "")
if rprefix and router.routes:
first_path = getattr(router.routes[0], "path", "")
if first_path.startswith(rprefix.rstrip("/") + "/"):
router.prefix = ""
app.include_router(router)
if rprefix and router.prefix == "":
router.prefix = rprefix # restore for bookkeeping
log.info("router_mounted path=%s", module_path)
return True
except Exception as exc: