You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the GitHub search to find a similar question and didn't find it.
I searched the FastAPI documentation, with the integrated search.
I already searched in Google "How to X in FastAPI" and didn't find any information.
I already read and followed all the tutorial in the docs and didn't find an answer.
I already checked if it is not related to FastAPI but to Pydantic.
I already checked if it is not related to FastAPI but to Swagger UI.
I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
I commit to help with one of those options 👆
Example Code
fromfastapiimportFastAPI, Request, statusfromstarlette.middleware.corsimportCORSMiddlewareapp=FastAPI(title='My API')
origins= ["http://localhost:3000", "https://localhost:3000", "https://private-frontend-url.amplifyapp.com", "http://private-frontend-url.amplifyapp.com"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"]
)
# All routes below here (both @app routes and other include_routes).
Description
I have my frontend (ReactJS) and backend (Python FastAPI) deployed separately on AWS. I keep getting this error message in my console when I open my frontend in Chrome and access my backend APIs:
I have tried multiple approaches based on what I have found on stackoverflow and other sources, but to no avail. Would appreciate guidance - this issue is deeply frustrating. Thanks.
Operating System
macOS, Other
Operating System Details
Localhost runs on macOS, actual deployment (which is the one I am having problem with) is on AWS
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
I have my frontend (ReactJS) and backend (Python FastAPI) deployed separately on AWS. I keep getting this error message in my console when I open my frontend in Chrome and access my backend APIs:
When running my backend and frontend separately on localhost, I see no issues at all.
I have shared my FastAPI code above. For added context, my ReactJS API Call is as follows:
Upon inspecting element on Chrome, here are the relevant headers captured by the browser:
I have tried multiple approaches based on what I have found on stackoverflow and other sources, but to no avail. Would appreciate guidance - this issue is deeply frustrating. Thanks.
Operating System
macOS, Other
Operating System Details
Localhost runs on macOS, actual deployment (which is the one I am having problem with) is on AWS
FastAPI Version
0.95.1
Python Version
3.10.7
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions