Add admin dashboard at / with bearer-token overview API

This commit is contained in:
2026-10-25 15:12:33 +08:00
parent 4acf226455
commit f5fcdd7bbb
9 changed files with 545 additions and 10 deletions
+9
View File
@@ -7,6 +7,7 @@ import (
"mime"
"net/http"
"strings"
"time"
)
// API is the HTTP control plane. Its answers match the recorded contract in
@@ -15,6 +16,10 @@ type API struct {
Store *Store
Hub *Hub
Domain string
AdminToken string // bearer token for /api/admin/*; empty disables it
StartedAt time.Time // for the uptime shown on the dashboard
Version string
}
func (a *API) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@@ -27,6 +32,10 @@ func (a *API) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`{"ok":true}`))
case path == "/openapi.json" && r.Method == http.MethodGet:
writeJSON(w, http.StatusOK, json.RawMessage(openapiStub))
case (path == "/" || path == "/admin") && r.Method == http.MethodGet:
a.dashboard(w, r)
case path == "/api/admin/overview" && r.Method == http.MethodGet:
a.adminOverviewHandler(w, r)
case path == "/api/tunnel" && r.Method == http.MethodPost:
a.createTunnel(w, r)
default: