view.py 485 B

123456789101112131415
  1. from fastapi import APIRouter
  2. from fastapi.responses import HTMLResponse
  3. import os
  4. from app.core.config import settings
  5. router = APIRouter()
  6. @router.get("/", response_class=HTMLResponse)
  7. async def read_root():
  8. # 读取 static/index.html 内容返回
  9. index_path = os.path.join(settings.STATIC_DIR, "index.html")
  10. if os.path.exists(index_path):
  11. with open(index_path, 'r', encoding='utf-8') as f:
  12. return f.read()
  13. return "<h1>Index.html not found</h1>"