Root path is applied 2 times when using root_path
See original GitHub issueHere is error:
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)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:10
- Comments:15 (3 by maintainers)
Top Results From Across the Web
Application Root Path of Spring Boot application
I need to upload a file to a directory e.g. uploads created in application main directory.
Read more >Path resolution in Quarkus
root -path , matching the original behavior. You can use an absolute path, e.g. /q , to serve non-application endpoints from the absolute...
Read more >Getting the Web Root Path and the Content Root Path in ASP ...
The web root path is the absolute path to the directory that contains the web-servable application content files. You can use either path...
Read more >Path.GetPathRoot Method (System.IO) | Microsoft Learn
Gets the root directory information from the path contained in the specified string. ... The following example demonstrates a use of the GetPathRoot...
Read more >Web App root directory - DevExpress Support
My licensing class is used in both a winforms and web XAF app so I've ... string licFile = rootPath + @"\Deep Blue...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This thread gave me some hints. I found one missing link that helped me solved the openapi.json ( not_found ) issue. Here is what worked for me
I am using nginx as proxy server and
FastAPI
withUvicorn
.FastAPI
andUvicorn
both have theroot_path
property and they both need to be set for nginx proxy to work properly.For the
openapi.json
issue, we need to passservers
property in theFastAPI
pointing to the proxy URL.Here is the sample code for
app
Here is a sample code for
nginx
setupim seeing similar irritating issues with both lambdas served over an api gatewith with a prefix path
and locally, using both root_path and a router with a prefix
reading the EXACT DOCS from here https://fastapi.tiangolo.com/advanced/behind-a-proxy/ and setting up the root_path…
also using router it isn’t working…
it always just serves things up as if the entire path is always the entire path regardless…
its incredibly infuriating reading doc after doc after doc and following all the the instructures verbatim and not a damn new thing making a damn bit of difference in how its served…
then finding people with the exact same issue being told ‘expected behavior not a bug’
then what are these worthless features for? how should they work?