Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

refactor: consolidate dashboard admin routes into RegisterAdminRoutes

Data5c37db55571c
diff --git a/internal/dashboard/admin.go b/internal/dashboard/admin.go
new file mode 100644
index 00000000..bb39f3b2
--- /dev/null
+++ b/internal/dashboard/admin.go
@@ -0,0 +1,31 @@
+package dashboard
+
+import (
+ "net/http"
+
+ "github.com/pinchtab/pinchtab/internal/activity"
+ "github.com/pinchtab/pinchtab/internal/httpx"
+)
+
+// AdminDeps holds the components needed for dashboard admin route registration.
+type AdminDeps struct {
+ ConfigAPI *ConfigAPI
+ AuthAPI *AuthAPI
+ AgentSessionAPI *AgentSessionAPI
+ Activity activity.Recorder
+ ServerMetrics func() map[string]any
+}
+
+// RegisterAdminRoutes registers all /api/* dashboard admin endpoints.
+func (d *Dashboard) RegisterAdminRoutes(mux *http.ServeMux, deps AdminDeps) {
+ d.RegisterHandlers(mux)
+ deps.ConfigAPI.RegisterHandlers(mux)
+ deps.AuthAPI.RegisterHandlers(mux)
+ if deps.AgentSessionAPI != nil {
+ deps.AgentSessionAPI.RegisterHandlers(mux)
+ }
+ activity.RegisterHandlers(mux, deps.Activity)
+ mux.HandleFunc("GET /api/metrics", func(w http.ResponseWriter, r *http.Request) {
+ httpx.JSON(w, 200, map[string]any{"metrics": deps.ServerMetrics()})
+ })
+}
diff --git a/internal/server/server.go b/internal/server/server.go
index 537097e0..5f9a1dc1 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -103,13 +103,15 @@ func RunDashboard(cfg *config.RuntimeConfig, version string) {
slog.Warn("restore dashboard agent activity", "err", err)
}
- dash.RegisterHandlers(mux)
- configAPI.RegisterHandlers(mux)
- authAPI.RegisterHandlers(mux)
- agentSessionAPI.RegisterHandlers(mux)
- profMgr.RegisterHandlers(mux)
liveActivity := newDashboardActivityRecorder(actStore, dash)
- activity.RegisterHandlers(mux, liveActivity)
+ dash.RegisterAdminRoutes(mux, dashboard.AdminDeps{
+ ConfigAPI: configAPI,
+ AuthAPI: authAPI,
+ AgentSessionAPI: agentSessionAPI,
+ Activity: liveActivity,
+ ServerMetrics: handlers.SnapshotMetrics,
+ })
+ profMgr.RegisterHandlers(mux)
syncCtx, syncCancel := context.WithCancel(context.Background())
go func() {
@@ -218,9 +220,6 @@ func RunDashboard(cfg *config.RuntimeConfig, version string) {
}
mux.HandleFunc("GET /health", configAPI.HandleHealth)
- mux.HandleFunc("GET /api/metrics", func(w http.ResponseWriter, r *http.Request) {
- httpx.JSON(w, 200, map[string]any{"metrics": handlers.SnapshotMetrics()})
- })
handler := handlers.RequestIDMiddleware(
activity.Middleware(