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.