-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Description
I'm mounting another ASGI application via mount but it always redirects from /another to /another/. I've found a similar issue with sub-routers (#414) which was solved.
Example
from fastapi import FastAPI
app = FastAPI()
another_app = FastAPI()
@another_app.get("")
def root():
return "alive"
app.mount("/another", another_app)Description
I'm using httpie for this example.
$ http localhost:8000/another
HTTP/1.1 307 Temporary Redirect
Transfer-Encoding: chunked
date: Mon, 04 Jan 2021 08:40:02 GMT
location: http://localhost:8000/another/
server: uvicorn
As you can see, a redirect to /another/ is happening.
I'm just using another FastAPI app as example here.
In my real world use-case the other application is the GraphQL ASGI app from the Ariadne GraphQL framework.
The behavior is the same. I've also verified that the redirect is triggered by FastAPI by setting a breakpoint in the GraphQL ASGI app which wasn't hit.
In the particular use-case shown above it's not even possible to hit the registered URL since it's registered on "" instead of "/". This doesn't apply to my real world use-case but I could imagine that there are other ASGI apps which don't respond on "/" but on "" only which couldn't be mounted in FastAPI at all due to this.
I realize that probably all ASGI apps register their root routes on "/" and not "" so probably everything is working by design here but in my case I'm getting a lot of redirects from /graphql to /graphql/ now which actually crashes the client app which doesn't handle redirects for security reasons.
Environment
-
OS: [e.g. Linux / Windows / macOS]: macOS
-
FastAPI Version [e.g. 0.3.0]: 0.63.0
-
Python version: 3.8