Spaces:
Sleeping
Sleeping
Move Vercel entry point to root api/index.py (Vercel Python convention)
Browse files- api/index.py +31 -0
- requirements.txt +8 -0
- vercel.json +12 -4
api/index.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Vercel serverless entry point for Civic City Hub backend.
|
| 3 |
+
|
| 4 |
+
Vercel Python serverless functions use WSGI. FastAPI is ASGI, so we use
|
| 5 |
+
Mangum — an ASGI-to-WSGI adapter — to bridge the gap.
|
| 6 |
+
|
| 7 |
+
Vercel looks for `app` (WSGI callable) in api/index.py at the project root.
|
| 8 |
+
"""
|
| 9 |
+
import os
|
| 10 |
+
import sys
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
|
| 13 |
+
# Signal to storage.py that we're on Vercel (use /tmp for SQLite)
|
| 14 |
+
os.environ["VERCEL"] = "1"
|
| 15 |
+
|
| 16 |
+
# Ensure the backend root is on sys.path so all imports resolve
|
| 17 |
+
_backend_root = Path(__file__).parent / "backend"
|
| 18 |
+
if str(_backend_root) not in sys.path:
|
| 19 |
+
sys.path.insert(0, str(_backend_root))
|
| 20 |
+
|
| 21 |
+
# Change working directory to backend root so relative paths work
|
| 22 |
+
os.chdir(str(_backend_root))
|
| 23 |
+
|
| 24 |
+
# Import the FastAPI app
|
| 25 |
+
from api.server import app as fastapi_app
|
| 26 |
+
|
| 27 |
+
# Wrap with Mangum for Vercel WSGI compatibility
|
| 28 |
+
from mangum import Mangum
|
| 29 |
+
|
| 30 |
+
# Vercel Python runtime looks for 'app' (WSGI callable)
|
| 31 |
+
app = Mangum(fastapi_app, lifespan="off")
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Vercel Python runtime requirements
|
| 2 |
+
# These are installed when the api/index.py serverless function is built
|
| 3 |
+
fastapi>=0.110.0
|
| 4 |
+
uvicorn[standard]>=0.27.0
|
| 5 |
+
openai>=1.12.0
|
| 6 |
+
cryptography>=41.0.0
|
| 7 |
+
httpx>=0.27.0
|
| 8 |
+
mangum>=0.17.0
|
vercel.json
CHANGED
|
@@ -5,13 +5,21 @@
|
|
| 5 |
"use": "@vercel/next"
|
| 6 |
},
|
| 7 |
{
|
| 8 |
-
"src": "
|
| 9 |
-
"use": "@vercel/python"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
}
|
| 11 |
],
|
| 12 |
"routes": [
|
| 13 |
-
{ "src": "/health", "dest": "
|
| 14 |
-
{ "src": "/api/(.*)", "dest": "
|
| 15 |
{ "handle": "filesystem" },
|
| 16 |
{ "src": "/(.*)", "dest": "frontend/$1" }
|
| 17 |
]
|
|
|
|
| 5 |
"use": "@vercel/next"
|
| 6 |
},
|
| 7 |
{
|
| 8 |
+
"src": "api/index.py",
|
| 9 |
+
"use": "@vercel/python",
|
| 10 |
+
"config": {
|
| 11 |
+
"functions": {
|
| 12 |
+
"api/index.py": {
|
| 13 |
+
"runtime": "python3.12@latest",
|
| 14 |
+
"maxDuration": 30
|
| 15 |
+
}
|
| 16 |
+
}
|
| 17 |
+
}
|
| 18 |
}
|
| 19 |
],
|
| 20 |
"routes": [
|
| 21 |
+
{ "src": "/health", "dest": "api/index.py" },
|
| 22 |
+
{ "src": "/api/(.*)", "dest": "api/index.py" },
|
| 23 |
{ "handle": "filesystem" },
|
| 24 |
{ "src": "/(.*)", "dest": "frontend/$1" }
|
| 25 |
]
|