mirror of
https://github.com/profullstack/agentbbs.git
synced 2026-12-01 17:24:48 +00:00
feat: public /api/health served by the agentbbs process (#143)
Some checks failed
CI / build (push) Has been cancelled
deploy / deploy (push) Has been cancelled
test / test (push) Has been cancelled
Some checks failed
CI / build (push) Has been cancelled
deploy / deploy (push) Has been cancelled
test / test (push) Has been cancelled
https://bbs.profullstack.com/ is Caddy's file_server, so a 200 there says nothing about the BBS. /api/health is now answered by agentbbs itself on its loopback HTTP listener (Caddy proxies it, like /verify) after a `select 1` on the SQLite store with a 3s cap: 200 {"status":"ok","db":"ok"} or 503 {"status":"error","db":"down"}, Cache-Control: no-store. Adds Store.Ping. For status.profullstack.com. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e95f2a30c3
commit
6cdc352d97
4 changed files with 65 additions and 0 deletions
34
cmd/agentbbs/health_test.go
Normal file
34
cmd/agentbbs/health_test.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/profullstack/agentbbs/internal/store"
|
||||
)
|
||||
|
||||
func TestHandleHealth(t *testing.T) {
|
||||
st, err := store.Open(filepath.Join(t.TempDir(), "test.db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a := &app{st: st}
|
||||
|
||||
rec := httptest.NewRecorder()
|
||||
a.handleHealth(rec, httptest.NewRequest(http.MethodGet, "/api/health", nil))
|
||||
if rec.Code != http.StatusOK || rec.Body.String() != `{"status":"ok","db":"ok"}` {
|
||||
t.Fatalf("healthy: %d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
if cc := rec.Header().Get("Cache-Control"); cc != "no-store" {
|
||||
t.Fatalf("Cache-Control = %q", cc)
|
||||
}
|
||||
|
||||
st.Close()
|
||||
rec = httptest.NewRecorder()
|
||||
a.handleHealth(rec, httptest.NewRequest(http.MethodGet, "/api/health", nil))
|
||||
if rec.Code != http.StatusServiceUnavailable || rec.Body.String() != `{"status":"error","db":"down"}` {
|
||||
t.Fatalf("closed store: %d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue