Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing to fix the request base URL via an env var #582

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

constantinius
Copy link
Contributor

Related Issue(s):

Description:

A new env var REQUEST_BASE_URL is introduced to fix the base URL to the supplied value. When this variable is not set, the usual way of determining the base URL is used.

PR Checklist:

  • pre-commit hooks pass locally
  • Tests pass (run make test)
  • Documentation has been updated to reflect changes, if applicable, and docs build successfully (run make docs)
  • Changes are added to the CHANGELOG.

@gadomski gadomski self-requested a review June 21, 2023 22:30
@gadomski gadomski linked an issue Jun 21, 2023 that may be closed by this pull request
stac_fastapi/types/tests/test_requests.py Outdated Show resolved Hide resolved
from starlette.requests import Request


def get_base_url(request: Request) -> str:
"""Get base URL with respect of APIRouter prefix."""
if base_url := os.environ.get("REQUEST_BASE_URL"):
return base_url

app = request.app
if not app.state.router_prefix:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a reason to not use the same mechanism as router_prefix, i.e. add a new base_url: Optional[str] attribute to the app state?

@vincentsarago
Copy link
Member

As for #636, I'm not convince we need this.

If the baseurl is not properly returned by starlette it usually mean there is a configuration issue in the proxy 🤔

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

Successfully merging this pull request may close these issues.

Allowing to fix the request base URL
4 participants