-
First Check
Commit to Help
Example Codefrom fastapi.applications import FastAPI
from fastapi.responses import FileResponse
from fastapi.routing import APIRouter
from starlette.routing import Route
frontend_router = APIRouter()
async def index_fallback(request):
return FileResponse("static/index.html")
frontend_router.mount("/", Route("/", index_fallback))
app = FastAPI()
app.include_router(frontend_router)DescriptionI expect being able to include a router which has applications mounted at the root. The problem seems to be that starlette strips any leading slashes from Operating SystemLinux Operating System DetailsOutput of
|
Beta Was this translation helpful? Give feedback.
Replies: 10 comments
-
|
@septatrix You are correct that you cannot do this through a router, but you can just add a route to the application itself and define it to use |
Beta Was this translation helpful? Give feedback.
-
|
use |
Beta Was this translation helpful? Give feedback.
-
Thanks, but that does not seem to support arbitrary ASGI apps. It not clear to me why the prefix check disallows my above example and I cannot think of a case where it would lead to problems if it were to accept the conditions in my example. |
Beta Was this translation helpful? Give feedback.
-
|
mount method need ASGI app not Route object, if you try with ASGI app it is work from fastapi import FastAPI
app = FastAPI()
@app.get("/test")
async def test():
return 'test'
app2 = FastAPI()
@app2.get("/test2")
def testapp2():
return 'test2'
app.mount("/", app2) |
Beta Was this translation helpful? Give feedback.
-
Yes but if I mount an ASGI app on |
Beta Was this translation helpful? Give feedback.
-
|
i got it, mount object return blank path and include_router raise that. i try something here: #5371 |
Beta Was this translation helpful? Give feedback.
-
|
fixed in this pr: #5373 |
Beta Was this translation helpful? Give feedback.
-
|
@BilalAlpaslan mounting an ASGI app on root works for me - at least the functional part of the API. In the Swagger UI docs however, I can't see the operations of the subapplication when mounting on root. |
Beta Was this translation helpful? Give feedback.
-
|
This should be solved on the latest FastAPI + Uvicorn. |
Beta Was this translation helpful? Give feedback.
-
|
It isn't. I'm still stumbling upon this in |
Beta Was this translation helpful? Give feedback.

This should be solved on the latest FastAPI + Uvicorn.