static.py 1.1 KB

123456789101112131415161718192021222324252627
  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_app_html():
  6. """Serve the main HTML file"""
  7. index_path = os.path.join("public","main", "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. async def serve_register_html():
  12. """Serve the register HTML file"""
  13. register_path = os.path.join("public", "register", "index.html")
  14. if not os.path.exists(register_path):
  15. raise HTTPException(status_code=404, detail="public/register/index.html not found.")
  16. return FileResponse(register_path)
  17. def mount_register_static_files(app):
  18. """Mount static files for the register page"""
  19. app.mount("/register/", StaticFiles(directory="public/register", html=False), name="register_static")
  20. def mount_main_static_files(app):
  21. """Mount static files"""
  22. app.mount("/express/", StaticFiles(directory="public/main", html=False), name="public_root_assets")