feat(backend): add /api/v1/ping liveness endpoint #634
3 changed files with 21 additions and 1 deletions
8
backend/app/api/v1/ping.py
Normal file
8
backend/app/api/v1/ping.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from fastapi import APIRouter
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/ping")
|
||||
async def ping() -> dict[str, bool]:
|
||||
return {"pong": True}
|
||||
|
|
@ -30,6 +30,7 @@ from app.api.v1 import (
|
|||
parcels,
|
||||
photos,
|
||||
pilot,
|
||||
ping,
|
||||
trade_in,
|
||||
users,
|
||||
)
|
||||
|
|
@ -86,7 +87,7 @@ app = FastAPI(title="GenDesign API", version="0.1.0", lifespan=lifespan)
|
|||
# Public paths без auth (/health, /docs, /openapi.json) пропускаем без проверки —
|
||||
# X-Authenticated-User там просто не приходит из Caddy.
|
||||
_ADMIN_API_RE = re.compile(r"^/api/v1/admin/")
|
||||
_PUBLIC_PATHS = frozenset({"/health", "/docs", "/redoc", "/openapi.json"})
|
||||
_PUBLIC_PATHS = frozenset({"/health", "/api/v1/ping", "/docs", "/redoc", "/openapi.json"})
|
||||
|
||||
|
||||
@app.middleware("http")
|
||||
|
|
@ -164,6 +165,7 @@ app.include_router(landing.router, prefix="/api/v1", tags=["landing"])
|
|||
app.include_router(pilot.router, prefix="/api/v1/pilot", tags=["pilot"])
|
||||
app.include_router(users.router, prefix="/api/v1", tags=["users"])
|
||||
app.include_router(me.router, prefix="/api/v1", tags=["me"])
|
||||
app.include_router(ping.router, prefix="/api/v1", tags=["ping"])
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
|
|
|
|||
10
backend/tests/test_ping.py
Normal file
10
backend/tests/test_ping.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.main import app
|
||||
|
||||
|
||||
def test_ping() -> None:
|
||||
client = TestClient(app)
|
||||
response = client.get("/api/v1/ping")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"pong": True}
|
||||
Loading…
Add table
Reference in a new issue