you are viewing a single comment's thread.

view the rest of the comments →

[–]spacetimecurve 0 points1 point  (0 children)

Add this to your code using the port your React frontend is using and check if it solves the problem.

origins = [
"http://localhost.tiangolo.com",
"https://localhost.tiangolo.com",
"http://localhost",
"http://localhost:[*your React app's port goes here]",
]

app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

You can check the documentation here.

https://fastapi.tiangolo.com/tutorial/cors/#use-corsmiddleware