nomyo-router/api/static.py

31 lines
1 KiB
Python
Raw Normal View History

2026-05-19 14:57:39 +02:00
"""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")