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:
parent
b454e9c3f7
commit
4712ec80ec
1 changed files with 11 additions and 0 deletions
11
app/mount.py
11
app/mount.py
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue