Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files
Procfile
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
web: uvicorn app:app --host 0.0.0.0 --port 7860
|
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from fastapi import FastAPI
|
| 3 |
+
from fastapi.staticfiles import StaticFiles
|
| 4 |
+
from fastapi.responses import FileResponse, JSONResponse
|
| 5 |
+
from backend.app import create_app, run_migrations
|
| 6 |
+
|
| 7 |
+
app: FastAPI = create_app()
|
| 8 |
+
|
| 9 |
+
@app.on_event("startup")
|
| 10 |
+
async def startup_event():
|
| 11 |
+
try:
|
| 12 |
+
run_migrations()
|
| 13 |
+
except Exception as e:
|
| 14 |
+
print("Migration error:", e)
|
| 15 |
+
|
| 16 |
+
FRONTEND_DIR = os.path.join(os.getcwd(), "frontend_dist")
|
| 17 |
+
if os.path.isdir(FRONTEND_DIR):
|
| 18 |
+
app.mount("/assets", StaticFiles(directory=os.path.join(FRONTEND_DIR, "assets")), name="assets")
|
| 19 |
+
@app.get("/{full_path:path}")
|
| 20 |
+
async def serve_spa(full_path: str):
|
| 21 |
+
index_path = os.path.join(FRONTEND_DIR, "index.html")
|
| 22 |
+
if os.path.exists(index_path):
|
| 23 |
+
return FileResponse(index_path)
|
| 24 |
+
return JSONResponse({"detail": "Frontend not built."}, status_code=501)
|
| 25 |
+
else:
|
| 26 |
+
@app.get("/")
|
| 27 |
+
async def root_info():
|
| 28 |
+
return {"message": "Backend running. Frontend not built."}
|