CUB-119: add GET /api/health endpoint to Chi router
Dev Build & Deploy / test-and-build (pull_request) Failing after 6s
Dev Build & Deploy / docker-build-push (pull_request) Has been skipped

This commit is contained in:
2026-05-23 20:09:24 -04:00
parent f3ce08497a
commit 4509b0c217
+15
View File
@@ -65,6 +65,21 @@ func New(deps *Dependencies) *chi.Mux {
// ── API v1 routes ────────────────────────────────────────────────────── // ── API v1 routes ──────────────────────────────────────────────────────
r.Route("/api", func(api chi.Router) { r.Route("/api", func(api chi.Router) {
// Health check (under /api)
api.Get("/health", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
status := "ok"
if deps.Pool != nil {
ctx, cancel := context.WithTimeout(r.Context(), 3*time.Second)
defer cancel()
if err := deps.Pool.Ping(ctx); err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
status = "db_unhealthy"
}
}
w.Write([]byte(`{"status":"` + status + `"}`))
})
// Agents CRUD // Agents CRUD
api.Route("/agents", func(agents chi.Router) { api.Route("/agents", func(agents chi.Router) {
agents.Get("/", deps.Handler.ListAgents) // GET /api/agents agents.Get("/", deps.Handler.ListAgents) // GET /api/agents