diff --git a/stac_fastapi/api/stac_fastapi/api/app.py b/stac_fastapi/api/stac_fastapi/api/app.py index bd03b4fe..08c430bb 100644 --- a/stac_fastapi/api/stac_fastapi/api/app.py +++ b/stac_fastapi/api/stac_fastapi/api/app.py @@ -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, @@ -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, @@ -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] diff --git a/stac_fastapi/api/tests/test_app_prefix.py b/stac_fastapi/api/tests/test_app_prefix.py index ea20c6c2..f2289ccf 100644 --- a/stac_fastapi/api/tests/test_app_prefix.py +++ b/stac_fastapi/api/tests/test_app_prefix.py @@ -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()