Fastapi: [QUESTION] Is there support for SCRIPT_NAME?

Created on 24 Aug 2019  路  7Comments  路  Source: tiangolo/fastapi

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.

answered question

All 7 comments

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:

  1. I learnt a thing or two about proxying with NGINX and traefik, so I could add that to the docs somewhere.
  2. I think that instead of manually configuring the 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_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.

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:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

updatatoday picture updatatoday  路  3Comments

tsdmrfth picture tsdmrfth  路  3Comments

scheung38 picture scheung38  路  3Comments

RogerioDosSantos picture RogerioDosSantos  路  3Comments

kkinder picture kkinder  路  3Comments