-
Notifications
You must be signed in to change notification settings - Fork 106
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
base_url
usage on landing page
#635
base_url
usage on landing page
#635
Conversation
@zachcoleman thanks for your PR, I need to catch up with stac-fastapi but is there any tests for this or should we make one? |
For this functionality, I think not. It just matches the usage around it. This seems like it'd just be adding tests for sake of adding tests. I think it will be more useful to probably test |
FYI: this ended up introducing a bug https://github.com/stac-utils/stac-fastapi-pgstac/pull/101/files#r1576403075 |
"href": urljoin( | ||
str(request.base_url), request.app.openapi_url.lstrip("/") | ||
), | ||
"href": urljoin(base_url, request.app.openapi_url.lstrip("/")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a user adds a router_prefix to the API, the base_url
as the prefix added in
stac-fastapi/stac_fastapi/types/stac_fastapi/types/requests.py
Lines 6 to 14 in f542278
def get_base_url(request: Request) -> str: | |
"""Get base URL with respect of APIRouter prefix.""" | |
app = request.app | |
if not app.state.router_prefix: | |
return str(request.base_url) | |
else: | |
return "{}{}/".format( | |
str(request.base_url), app.state.router_prefix.lstrip("/") | |
) |
The issue is that, when we create the fastapi app
stac-fastapi/stac_fastapi/api/stac_fastapi/api/app.py
Lines 75 to 85 in f542278
app: FastAPI = attr.ib( | |
default=attr.Factory( | |
lambda self: FastAPI( | |
openapi_url=self.settings.openapi_url, | |
docs_url=self.settings.docs_url, | |
redoc_url=None, | |
), | |
takes_self=True, | |
), | |
converter=update_openapi, | |
) |
we set the openapi_url to either /api
or to what the user has set the openapi_url
settings.
so by default we register the openapi to /api
but here when we do urljoin(base_url, request.app.openapi_url.lstrip("/")),
, we endup with /{base_url}/{router_prefix}/api
Related Issue(s):
Description:
Adds the
base_url
usage for two links where it was missing.PR Checklist:
pre-commit
hooks pass locallymake test
)make docs
)