-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.py
More file actions
42 lines (36 loc) · 1.25 KB
/
index.py
File metadata and controls
42 lines (36 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from vercel import init_vercel
# Initialize Vercel environment
init_vercel()
# Import after Vercel env initialization because app import validates secrets.
from app import create_app
# Create Flask app
app = create_app()
def handler(request):
"""Handle Vercel serverless function requests."""
try:
with app.test_client() as test_client:
# Convert Vercel request to Flask request context
method = request.get('method', 'GET')
path = request.get('path', '/')
headers = request.get('headers', {})
body = request.get('body', '')
# Make the request to Flask app
response = test_client.open(
path,
method=method,
headers=headers,
data=body
)
# Return response in Vercel format
return {
'statusCode': response.status_code,
'headers': dict(response.headers),
'body': response.get_data(as_text=True)
}
except Exception as e:
# Return error response
return {
'statusCode': 500,
'body': str(e),
'headers': {'Content-Type': 'text/plain'}
}