'Mount multiple sub-apps with the same path in FastAPI
I have two fastapi sub apps, one called api_app and the other admin_app. I want to mount those 2 apps to my main app like that:
app.mount('/', api_app, name='api')
app.mount('/', admin_app, name='admin_api')
When I try to access an endpoint from the app admin_app I get Not Found response.
I know this can be solved using APIRouter but in my case I need to use FastAPI app because I need to add middlwares to api_app.
I think the solution is to override the 404 exception handler of the first app, but I don't know how to pass the request to the next app.
Solution 1:[1]
try to add path name into your mounted app like:
app.mount('/api', api_app, name='api')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ashkan Goleh Pour |
