feat: add health check endpoint and update Makefile for health URL
This commit is contained in:
@@ -7,7 +7,7 @@ GO ?= go
|
||||
PNPM ?= pnpm
|
||||
GOOS ?= $(shell $(GO) env GOOS)
|
||||
GOARCH ?= $(shell $(GO) env GOARCH)
|
||||
DEV_SERVER_URL ?= http://127.0.0.1:8083
|
||||
DEV_SERVER_URL ?= http://127.0.0.1:8083/api/health
|
||||
LANCEDB_VERSION ?= v0.1.2
|
||||
LANCEDB_DOWNLOAD_SCRIPT ?= https://raw.githubusercontent.com/lancedb/lancedb-go/main/scripts/download-artifacts.sh
|
||||
LANCEDB ?= 0
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"agent-desk/internal/ai/mcps"
|
||||
_ "agent-desk/internal/ai/runtime"
|
||||
"agent-desk/internal/handlers/api"
|
||||
"agent-desk/internal/middleware"
|
||||
"agent-desk/internal/pkg/config"
|
||||
"agent-desk/internal/pkg/ginx"
|
||||
@@ -154,6 +155,7 @@ func addRouter(app *gin.Engine) {
|
||||
app.Any("/api/mcp", gin.WrapH(mcps.NewHTTPHandler()))
|
||||
|
||||
apiGroup := app.Group("/api")
|
||||
apiGroup.GET("/health", api.Health)
|
||||
registerApiAuthRoutes(apiGroup.Group("/auth"))
|
||||
registerApiChannelRoutes(apiGroup.Group("/channel"))
|
||||
registerApiCustomerRoutes(apiGroup.Group("/customer"))
|
||||
|
||||
@@ -32,6 +32,7 @@ func TestNewServerRegistersGinRoutes(t *testing.T) {
|
||||
|
||||
expected := []string{
|
||||
http.MethodPost + " /api/auth/login",
|
||||
http.MethodGet + " /api/health",
|
||||
http.MethodGet + " /api/auth/oidc_login",
|
||||
http.MethodGet + " /api/auth/oidc_callback",
|
||||
http.MethodPost + " /api/auth/oidc_exchange",
|
||||
@@ -50,6 +51,45 @@ func TestNewServerRegistersGinRoutes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewServerHealthEndpointIsPublic(t *testing.T) {
|
||||
config.SetCurrent(&config.Config{
|
||||
Storage: config.StorageConfig{
|
||||
Local: config.LocalStorageConfig{
|
||||
Root: "storage",
|
||||
BaseURL: "/storage",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
app, err := NewServer()
|
||||
if err != nil {
|
||||
t.Fatalf("NewServer() error = %v", err)
|
||||
}
|
||||
|
||||
rec := httptest.NewRecorder()
|
||||
app.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/api/health", nil))
|
||||
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status=%d want %d, body=%s", rec.Code, http.StatusOK, rec.Body.String())
|
||||
}
|
||||
|
||||
var body struct {
|
||||
Success bool `json:"success"`
|
||||
Data struct {
|
||||
Status string `json:"status"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
|
||||
t.Fatalf("unmarshal response: %v", err)
|
||||
}
|
||||
if !body.Success {
|
||||
t.Fatalf("success=false, body=%s", rec.Body.String())
|
||||
}
|
||||
if body.Data.Status != "ok" {
|
||||
t.Fatalf("status=%q want ok", body.Data.Status)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewServerExposesPublicAuthOptions(t *testing.T) {
|
||||
config.SetCurrent(&config.Config{
|
||||
Storage: config.StorageConfig{
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"agent-desk/internal/pkg/httpx"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type healthResponse struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
func Health(ctx *gin.Context) {
|
||||
httpx.WriteJSON(ctx, &healthResponse{Status: "ok"})
|
||||
}
|
||||
Reference in New Issue
Block a user