Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions stac_fastapi/api/stac_fastapi/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,13 @@ def register_core(self) -> None:
def add_health_check(self) -> None:
"""Add a health check."""

mgmt_router = APIRouter(prefix=self.app.state.router_prefix)

async def ping():
"""Liveliness probe."""
return {"message": "PONG"}

self.app.router.add_api_route(
mgmt_router.add_api_route(
name="Ping",
path="/_mgmt/ping",
response_model=Dict,
Expand All @@ -389,10 +391,9 @@ async def ping():
response_class=self.response_class,
methods=["GET"],
endpoint=ping,
tags=["Liveliness/Readiness"],
)

self.app.router.add_api_route(
mgmt_router.add_api_route(
name="Health",
path="/_mgmt/health",
response_model=Dict,
Expand All @@ -406,8 +407,8 @@ async def ping():
response_class=self.response_class,
methods=["GET"],
endpoint=self.health_check,
tags=["Liveliness/Readiness"],
)
self.app.include_router(mgmt_router, tags=["Liveliness/Readiness"])

def add_route_dependencies(
self, scopes: List[Scope], dependencies: List[Depends]
Expand Down
3 changes: 3 additions & 0 deletions stac_fastapi/api/tests/test_app_prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def test_api_prefix(TestCoreClient, prefix):
)

with TestClient(api.app, base_url="http://stac.io") as client:
ping = client.get(f"{prefix}/_mgmt/ping")
assert ping.status_code == 200, ping.json() == {"message": "PONG"}

landing = client.get(f"{prefix}/")
assert landing.status_code == 200, landing.json()

Expand Down