From 6062575a1c1ddc048792add6e62bd8a96a4c4a46 Mon Sep 17 00:00:00 2001 From: scanash00 Date: Thu, 25 Jun 2026 09:06:26 +0000 Subject: [PATCH] more fixes with healtchecks and stuff --- Dockerfile | 10 ++++++++++ backend/internal/api/handler.go | 8 ++++++++ 2 file(s) changed, 18 insertion(s)(+), 0 deletion(s)(-) diff --git a/Dockerfile b/Dockerfile --- a/Dockerfile +++ b/Dockerfile @@ -49,6 +49,16 @@ PORT=$API_PORT ./margin-server & api_pid=$! + +until wget -qO- "http://localhost:$API_PORT/health" >/dev/null 2>&1; do + if ! kill -0 "$api_pid" 2>/dev/null; then + echo "API exited before becoming ready" + exit 1 + fi + echo "Waiting for API..." + sleep 0.5 +done + node ./dist/server/entry.mjs & web_pid=$! diff --git a/backend/internal/api/handler.go b/backend/internal/api/handler.go --- a/backend/internal/api/handler.go +++ b/backend/internal/api/handler.go @@ -263,6 +263,14 @@ func (h *Handler) Health(w http.ResponseWriter, r *http.Request) { w.Header().Set("Cache-Control", "no-cache") + + ctx, cancel := context.WithTimeout(r.Context(), 2*time.Second) + defer cancel() + if err := h.db.Pool().Ping(ctx); err != nil { + WriteJSON(w, http.StatusServiceUnavailable, map[string]string{"status": "unavailable", "reason": "database"}) + return + } + WriteSuccess(w, map[string]string{"status": "ok", "version": "1.0"}) } -- tangled.sh