feat: add embedded web dashboard for remote server
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -23,6 +23,7 @@ func NewHandler(store *Store, token string) http.Handler {
|
||||
}
|
||||
})))
|
||||
mux.Handle("/api/v1/meta", bearerAuth(token, http.HandlerFunc(handleMeta(store))))
|
||||
mux.Handle("/", webHandler())
|
||||
return mux
|
||||
}
|
||||
|
||||
|
||||
@@ -131,6 +131,28 @@ func TestHTTPGetAgentFilter(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTTPGetRootNoAuth200(t *testing.T) {
|
||||
store := openTestStore(t)
|
||||
srv := httptest.NewServer(NewHandler(store, "secret"))
|
||||
defer srv.Close()
|
||||
|
||||
resp, err := http.Get(srv.URL + "/")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("status: got %d want %d", resp.StatusCode, http.StatusOK)
|
||||
}
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(body), "agent-notify") {
|
||||
t.Fatalf("expected dashboard HTML, got: %q", string(body[:min(80, len(body))]))
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTTPHealthz200(t *testing.T) {
|
||||
store := openTestStore(t)
|
||||
srv := httptest.NewServer(NewHandler(store, "secret"))
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/longbin/agent-notify/web"
|
||||
)
|
||||
|
||||
func webHandler() http.Handler {
|
||||
return web.Handler()
|
||||
}
|
||||
Reference in New Issue
Block a user