Description
Is the use of SCRIPT_NAME is fully supported in FastAPI? Or is there a different strategy for mounting the main application on a URL path?
Additional context
I have created a demo project with an extensive explanation of all the steps I tried.
I'm deploying my applications with gunicorn and uvicorn. So it is possibly also a uvicorn issue. Whereas daphne has added support for SCRIPT_NAME, I can find no mention of it in the uvicorn docs or issues.
I found a solution but would still request a change to FastAPI. I'll edit this comment in a bit. I need to deploy the solution before explaining it here :wink:
So I found out that I need to configure the root_path rather than the SCRIPT_NAME. You can read up on the full solution strategy on the root-path branch. Which basically answers this question.
Follow ups:
openapi_prefix for the main app, it should automatically pick up on a configured root_path and use that (in addition to what is manually set). If you agree, I can try to make a PR.Thanks to @euri10 for the discussion on gitter.
@Midnighter I'm glad you solved your issue!
You might want to check the docs for using apps behind a proxy: https://fastapi.tiangolo.com/advanced/sub-applications-proxy/
I did look at that section a fair bit.
What do you think about my suggestion above?
I think that instead of manually configuring the
openapi_prefixfor the main app, it should automatically pick up on a configuredroot_pathand use that (in addition to what is manually set). If you agree, I can try to make a PR.
Bump.
To me it makes sense to automatically include the root path as an openapi prefix and I'm happy to make the required changes.
Hey @Midnighter ! There's now support for root_path in FastAPI :tada: https://fastapi.tiangolo.com/advanced/sub-applications/
I was happy to see it in the latest release notes! Very cool :slightly_smiling_face: