Skip to content

Conversation

@shaiarmis
Copy link

In FastAPI, when the root_path is configured, it's included both in the base_url and in the path:

root_path = "/api/v1"
base_url  = "https://acme.com/api/v1/"
path      = "/api/v1/my/endpoint"

To avoid reporting https://acme.com/api/v1/api/v1/my_endpoint, this PR adds trimming of the redundant root_path.

🧰 Changes

  1. When constructing a URL, check if the request has root_path
  2. If it does, and the path indeed starts with it, trim it from the path.

🧬 QA & Testing

Any FastAPI setup with the root_path configured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant