| 12345678910111213141516171819202122232425262728293031323334 |
- import os
- from fastapi import HTTPException
- from fastapi.responses import HTMLResponse, FileResponse
- from fastapi.staticfiles import StaticFiles
- async def serve_app_html():
- """Serve the main HTML file"""
- index_path = os.path.join("public","main", "index.html")
- if not os.path.exists(index_path):
- raise HTTPException(status_code=404, detail="public/index.html not found.")
- return FileResponse(index_path)
- async def serve_register_html():
- """Serve the register HTML file"""
- register_path = os.path.join("public", "register", "index.html")
- if not os.path.exists(register_path):
- raise HTTPException(status_code=404, detail="public/register/index.html not found.")
- return FileResponse(register_path)
- def mount_register_static_files(app):
- """Mount static files for the register page"""
- app.mount("/register/", StaticFiles(directory="public/register", html=False), name="register_static")
- def mount_main_static_files(app):
- """Mount static files"""
- app.mount("/express/", StaticFiles(directory="public/main", html=False), name="public_root_assets")
- def serve_image(image_path: str):
- """Serve images from the public/images directory"""
- image_full_path = os.path.join("public", "images", image_path)
- if not os.path.exists(image_full_path):
- raise HTTPException(status_code=404, detail=f"Image '{image_path}' not found.")
- return FileResponse(image_full_path)
|