Root path is applied 2 times when using root_path
mindej opened this issue · comments
Python 3.7.8
fastapi 0.63.0
Run configuration:
uvicorn.run("app:app", host="0.0.0.0", port=port, reload=True)
I think the error is in the path here is console log:
127.0.0.1:54913 - "GET /api/v1/api/v1/openapi.json HTTP/1.1" 404 Not Found
Here is double path: /api/v1/api/v1/
Doc path is wrong http://localhost:8080/docs I expect it to be: http://localhost:8080/api/v1/docs
Here is the test code to reproduce 'test_app.py' file:
import uvicorn
import json
from fastapi import FastAPI, APIRouter, Response
from fastapi.responses import RedirectResponse
app = FastAPI(title="Root path test", root_path="/api/v1")
@app.post("/test-call ", tags=["test"])
def ping():
return Response(
json.dumps(dict(ping='pong')),
headers={'Content-Type':'application/json'})
@app.get("/")
def read_typer():
return RedirectResponse('/docs')
if __name__ == "__main__":
uvicorn.run("test_app:app", host="0.0.0.0", port=8080, reload=True)
root_path
is to be used behind a proxy, check the docs here, including how to test that with Traefik: https://fastapi.tiangolo.com/advanced/behind-a-proxy/
Sorry for the long delay! 🙈 I wanted to personally address each issue/PR and they piled up through time, but now I'm checking each one in order.
Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.