11from contextlib import asynccontextmanager
22
3- from fastapi import FastAPI , Request
3+ from fastapi import FastAPI , Request , status
44from httpx import AsyncClient
55from starlette .middleware .cors import CORSMiddleware
6+ from starlette .responses import JSONResponse
67
78from app .config import settings
89from app .middleware import log_request_middleware
9- from app .utils import build_merged_openapi , proxy_request
10+ from app .utils import build_merged_openapi , proxy_request , json_encoder
11+ from app .limiter import limiter
1012
1113
1214@asynccontextmanager
@@ -30,8 +32,7 @@ async def lifespan(app: FastAPI):
3032 }
3133 yield
3234
33-
34- app = FastAPI (title = "Secure Chain Gateway" , docs_url = None , lifespan = lifespan )
35+ app = FastAPI (title = "Secure Chain Gateway" , docs_url = settings .DOCS_URL , lifespan = lifespan )
3536app .middleware ("http" )(log_request_middleware )
3637app .add_middleware (
3738 CORSMiddleware ,
@@ -42,13 +43,34 @@ async def lifespan(app: FastAPI):
4243)
4344
4445
46+ @app .get (
47+ "/health" ,
48+ summary = "Health Check" ,
49+ description = "Check the status of the API." ,
50+ response_description = "API status." ,
51+ tags = ["Secure Chain Gateway Health" ]
52+ )
53+ @limiter .limit ("25/minute" )
54+ async def health_check (request : Request ):
55+ return JSONResponse (
56+ status_code = status .HTTP_200_OK , content = json_encoder (
57+ {
58+ "code" : "healthy" ,
59+ }
60+ )
61+ )
62+
63+
4564@app .api_route ("/auth/{path:path}" , methods = ["GET" , "POST" , "PUT" , "DELETE" , "PATCH" ])
65+ @limiter .limit ("25/minute" )
4666async def proxy_auth (path : str , request : Request ):
4767 url = f"http://securechain-auth:8000/{ path } "
4868 return await proxy_request (url , request )
4969
5070
5171@app .api_route ("/depex/{path:path}" , methods = ["GET" , "POST" , "PUT" , "DELETE" , "PATCH" ])
72+ @limiter .limit ("25/minute" )
5273async def proxy_depex (path : str , request : Request ):
5374 url = f"http://securechain-depex:8000/{ path } "
5475 return await proxy_request (url , request )
76+
0 commit comments