File tree Expand file tree Collapse file tree 4 files changed +38
-10
lines changed Expand file tree Collapse file tree 4 files changed +38
-10
lines changed Original file line number Diff line number Diff line change 1111from fastapi import FastAPI
1212
1313from .config import Settings
14- from .handlers import ReverseProxyHandler
14+ from .handlers import ReverseProxyHandler , HealthzHandler
1515from .middleware import (
1616 AddProcessTimeHeaderMiddleware ,
1717 ApplyCql2FilterMiddleware ,
@@ -58,12 +58,9 @@ def create_app(settings: Optional[Settings] = None) -> FastAPI:
5858 oidc_config_url = settings .oidc_discovery_url ,
5959 )
6060
61- if settings .debug :
62- app .add_api_route (
63- "/_debug" ,
64- lambda : {"settings" : settings },
65- methods = ["GET" ],
66- )
61+ if settings .healthz_prefix :
62+ healthz_handler = HealthzHandler (upstream_url = str (settings .upstream_url ))
63+ app .include_router (healthz_handler .router , prefix = "/healthz" )
6764
6865 # Catchall for any endpoint
6966 proxy_handler = ReverseProxyHandler (upstream = str (settings .upstream_url ))
Original file line number Diff line number Diff line change @@ -28,12 +28,11 @@ def __call__(self):
2828class Settings (BaseSettings ):
2929 """Configuration settings for the STAC Auth Proxy."""
3030
31- debug : bool = False
32-
3331 upstream_url : HttpUrl = HttpUrl (url = "https://earth-search.aws.element84.com/v1" )
3432 oidc_discovery_url : HttpUrl
3533
3634 # Endpoints
35+ healthz_prefix : str = Field (pattern = _PREFIX_PATTERN , default = "/healthz" )
3736 default_public : bool = False
3837 private_endpoints : EndpointMethods = {
3938 # https://github.com/stac-api-extensions/collection-transaction/blob/v1.0.0-beta.1/README.md#methods
Original file line number Diff line number Diff line change 11"""Handlers to process requests."""
22
33from .reverse_proxy import ReverseProxyHandler
4+ from .healthz import HealthzHandler
45
5- __all__ = ["ReverseProxyHandler" ]
6+ __all__ = ["ReverseProxyHandler" , "HealthzHandler" ]
Original file line number Diff line number Diff line change 1+ """Health check endpoints."""
2+
3+ from dataclasses import dataclass , field
4+
5+ from fastapi import APIRouter
6+ from httpx import AsyncClient
7+
8+
9+ @dataclass
10+ class HealthzHandler :
11+ """Handler for health check endpoints."""
12+
13+ upstream_url : str
14+ router : APIRouter = field (init = False )
15+
16+ def __post_init__ (self ):
17+ """Initialize the router."""
18+ self .router = APIRouter ()
19+ self .router .add_api_route ("/" , self .healthz , methods = ["GET" ])
20+ self .router .add_api_route ("/upstream" , self .healthz_upstream , methods = ["GET" ])
21+
22+ async def healthz (self ):
23+ """Basic health check endpoint."""
24+ return {"status" : "ok" }
25+
26+ async def healthz_upstream (self ):
27+ """Check health of upstream STAC API."""
28+ async with AsyncClient () as client :
29+ response = await client .get (self .upstream_url )
30+ response .raise_for_status ()
31+ return {"status" : "ok" , "code" : response .status_code }
You can’t perform that action at this time.
0 commit comments