From 4509b0c2174ad189f4da596620f4a5ccd2ebe367 Mon Sep 17 00:00:00 2001 From: dex-bot Date: Sat, 23 May 2026 20:09:24 -0400 Subject: [PATCH] CUB-119: add GET /api/health endpoint to Chi router --- go-backend/internal/router/router.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/go-backend/internal/router/router.go b/go-backend/internal/router/router.go index 6532b8b..8396732 100644 --- a/go-backend/internal/router/router.go +++ b/go-backend/internal/router/router.go @@ -65,6 +65,21 @@ func New(deps *Dependencies) *chi.Mux { // ── API v1 routes ────────────────────────────────────────────────────── 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 api.Route("/agents", func(agents chi.Router) { agents.Get("/", deps.Handler.ListAgents) // GET /api/agents