From 28abad27c6bbed7507b1952d97eeca3d6ab40ae5 Mon Sep 17 00:00:00 2001 From: "alexei.dolgolyov" Date: Sat, 28 Mar 2026 13:48:20 +0300 Subject: [PATCH] fix: SSE flusher support, null-safe API responses - Add Flush() to statusRecorder so SSE works through logging middleware - Return empty array instead of null for empty project lists - Fixes 500 on /api/events and null.length crash on dashboard --- internal/api/middleware.go | 7 +++++++ internal/api/projects.go | 3 +++ 2 files changed, 10 insertions(+) diff --git a/internal/api/middleware.go b/internal/api/middleware.go index 30d6401..07f7345 100644 --- a/internal/api/middleware.go +++ b/internal/api/middleware.go @@ -72,3 +72,10 @@ func (r *statusRecorder) WriteHeader(code int) { r.status = code r.ResponseWriter.WriteHeader(code) } + +// Flush delegates to the underlying ResponseWriter if it supports http.Flusher (needed for SSE). +func (r *statusRecorder) Flush() { + if f, ok := r.ResponseWriter.(http.Flusher); ok { + f.Flush() + } +} diff --git a/internal/api/projects.go b/internal/api/projects.go index 029f19d..8aa73de 100644 --- a/internal/api/projects.go +++ b/internal/api/projects.go @@ -27,6 +27,9 @@ func (s *Server) listProjects(w http.ResponseWriter, r *http.Request) { respondError(w, http.StatusInternalServerError, "failed to list projects: "+err.Error()) return } + if projects == nil { + projects = []store.Project{} + } respondJSON(w, http.StatusOK, projects) }