refac: modularize apis VII
This commit is contained in:
parent
e74f5d1ba6
commit
4b5a70e787
7 changed files with 2244 additions and 2108 deletions
30
api/static.py
Normal file
30
api/static.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
"""Static-asset and dashboard routes."""
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Request
|
||||
from starlette.responses import HTMLResponse, RedirectResponse
|
||||
|
||||
# Directory containing static files (resolved relative to project root).
|
||||
STATIC_DIR = Path(__file__).resolve().parent.parent / "static"
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/favicon.ico")
|
||||
async def redirect_favicon():
|
||||
return RedirectResponse(url="/static/favicon.ico")
|
||||
|
||||
|
||||
@router.get("/", response_class=HTMLResponse)
|
||||
async def index(request: Request):
|
||||
"""
|
||||
Render the dynamic NOMYO Router dashboard listing the configured endpoints
|
||||
and the models details, availability & task status.
|
||||
"""
|
||||
index_path = STATIC_DIR / "index.html"
|
||||
try:
|
||||
return HTMLResponse(content=index_path.read_text(encoding="utf-8"), status_code=200)
|
||||
except FileNotFoundError:
|
||||
raise HTTPException(status_code=404, detail="Page not found")
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500, detail="Internal server error")
|
||||
Loading…
Add table
Add a link
Reference in a new issue