Skip to content

Commit a3b96c8

Browse files
committed
Update FastAPI application with proper CORS and port settings
1 parent a053184 commit a3b96c8

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

application.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
from fastapi import FastAPI
2+
from fastapi.middleware.cors import CORSMiddleware
23
from mangum import Mangum
34
from backend.app.main import app
45

56
# Update the application instance name to match the EB configuration
67
application = app
78

8-
# Add CORS middleware
9-
from fastapi.middleware.cors import CORSMiddleware
9+
# Add CORS middleware with specific origins
10+
origins = [
11+
"https://getgit789.github.io",
12+
"https://getgit789.github.io/python-interpreter-online/",
13+
"http://localhost:5000",
14+
"http://127.0.0.1:5000"
15+
]
16+
1017
application.add_middleware(
1118
CORSMiddleware,
12-
allow_origins=["*"], # Temporarily allow all origins for testing
19+
allow_origins=origins,
1320
allow_credentials=True,
1421
allow_methods=["*"],
1522
allow_headers=["*"],
23+
expose_headers=["*"],
24+
max_age=3600
1625
)
1726

1827
# Create handler for AWS Lambda
1928
handler = Mangum(application)
2029

2130
if __name__ == "__main__":
2231
import uvicorn
23-
uvicorn.run(application, host="0.0.0.0", port=5000)
32+
uvicorn.run(application, host="0.0.0.0", port=80)

0 commit comments

Comments
 (0)