Spaces:
Sleeping
Sleeping
File size: 826 Bytes
d2fb92d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
from fastapi import FastAPI
from fastapi.responses import FileResponse
import os
app = FastAPI()
# Define the path to the Angular build output
frontend_dir = os.path.abspath("frontend")
# Serve the Angular index.html file for all root paths
@app.get("/{full_path:path}")
def serve_frontend(full_path: str):
file_path = os.path.join(frontend_dir, full_path)
if os.path.exists(file_path) and os.path.isfile(file_path):
return FileResponse(file_path)
else:
# Serve the index.html for any unmatched routes (to handle Angular routing)
return FileResponse(os.path.join(frontend_dir, "index.html"))
# Serve static assets (e.g., JS, CSS, images)
@app.get("/static/{full_path:path}")
def serve_static(full_path: str):
return FileResponse(os.path.join(frontend_dir, "static", full_path)) |