0

I've a working example of serving create-react-app build with FastApi.

app.mount("/static", StaticFiles(directory="static/static", html=True), name="static")

templates = Jinja2Templates(directory="static")

app.include_router(auth.router)
app.include_router(api.router)


@app.route("/{path:path}")
async def read_root(request: Request, path: str = None):
    return templates.TemplateResponse("index.html", {"request": request})

React app routing is working, and sides that use get methods from backend work as well, but the post method that should return a token does not work and returns 405 error, method not allowed.

i have tried doing things like these: https://github.com/tiangolo/fastapi/issues/130#issuecomment-491379252 yet this doesn't help at all.

2
  • Have you specified CORS origins? fastapi.tiangolo.com/tutorial/cors Commented Jan 21, 2024 at 17:51
  • Yes i have specified it but it and the error seemed to be that i left one trailing slash "/" in the URL for getting the token. After removing it al is fine Commented Jan 21, 2024 at 19:11

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.