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

base_url usage on landing page #635

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions stac_fastapi/types/stac_fastapi/types/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,7 @@ async def landing_page(self, **kwargs) -> stac_types.LandingPage:
"rel": "service-desc",
"type": "application/vnd.oai.openapi+json;version=3.0",
"title": "OpenAPI service description",
"href": urljoin(
str(request.base_url), request.app.openapi_url.lstrip("/")
),
"href": urljoin(base_url, request.app.openapi_url.lstrip("/")),
Copy link
Member

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

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

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

}
)

Expand All @@ -593,9 +591,7 @@ async def landing_page(self, **kwargs) -> stac_types.LandingPage:
"rel": "service-doc",
"type": "text/html",
"title": "OpenAPI service documentation",
"href": urljoin(
str(request.base_url), request.app.docs_url.lstrip("/")
),
"href": urljoin(base_url, request.app.docs_url.lstrip("/")),
}
)

Expand Down
Loading