static.py 576 B

1234567891011121314151617
  1. import os
  2. from fastapi import HTTPException
  3. from fastapi.responses import HTMLResponse, FileResponse
  4. from fastapi.staticfiles import StaticFiles
  5. async def serve_index_html():
  6. """Serve the main HTML file"""
  7. index_path = os.path.join("public", "index.html")
  8. if not os.path.exists(index_path):
  9. raise HTTPException(status_code=404, detail="public/index.html not found.")
  10. return FileResponse(index_path)
  11. def mount_static_files(app):
  12. """Mount static files"""
  13. app.mount("/", StaticFiles(directory="public", html=False), name="public_root_assets")