Spaces:
Sleeping
Sleeping
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 | |
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) | |
def serve_static(full_path: str): | |
return FileResponse(os.path.join(frontend_dir, "static", full_path)) |