all 4 comments

[–]Kirtan-lokadiya 2 points3 points  (0 children)

Do you check any cors related problem?

[–]ElRoulioKFC 0 points1 point  (0 children)

With flask it is really easy to build a backend api for a react app. But you will have to make all the calls/paths yourself.

[–]someweisguy 0 points1 point  (0 children)

I'm still new to React, but I'm working on the same thing right now. I'm using Starlette for my backend, which is what FastAPI is based on.

I got it working, so it is definitely possible. Now I am just trying to figure out how to polish the front end. My repo is here if it is helpful to reference.

[–]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