Spaces:
Running
Running
import os | |
from fastapi import FastAPI | |
from fastapi.staticfiles import StaticFiles | |
from fastapi.responses import FileResponse, JSONResponse | |
from backend.app import create_app, run_migrations | |
app: FastAPI = create_app() | |
async def startup_event(): | |
try: | |
run_migrations() | |
except Exception as e: | |
print("Migration error:", e) | |
FRONTEND_DIR = os.path.join(os.getcwd(), "frontend_dist") | |
if os.path.isdir(FRONTEND_DIR): | |
app.mount("/assets", StaticFiles(directory=os.path.join(FRONTEND_DIR, "assets")), name="assets") | |
async def serve_spa(full_path: str): | |
index_path = os.path.join(FRONTEND_DIR, "index.html") | |
if os.path.exists(index_path): | |
return FileResponse(index_path) | |
return JSONResponse({"detail": "Frontend not built."}, status_code=501) | |
else: | |
async def root_info(): | |
return {"message": "Backend running. Frontend not built."} | |