-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtopology_ui.py
More file actions
21 lines (15 loc) · 949 Bytes
/
Copy pathtopology_ui.py
File metadata and controls
21 lines (15 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from pathlib import Path
from fastapi import Depends, FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from starlette.staticfiles import StaticFiles
from starlette.routing import Mount
_TEMPLATES = Jinja2Templates(directory=str(Path(__file__).resolve().parent / "templates"))
def register_topology_ui(app: FastAPI, admin_dependency):
"""Register topology UI route and static assets without changing API contracts."""
has_static_mount = any(isinstance(route, Mount) and route.path == "/static" for route in app.routes)
if not has_static_mount:
app.mount("/static", StaticFiles(directory=str(Path(__file__).resolve().parent / "static")), name="static")
@app.get("/ui/topology", response_class=HTMLResponse)
async def ui_topology(request: Request, _=Depends(admin_dependency)):
return _TEMPLATES.TemplateResponse("topology.html", {"request": request})