diff --git a/README.md b/README.md index a046a25..c314fc8 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ All `/api/v1` routes require `Authorization: Bearer `. | GET | `/api/v1/activities?from=&to=&source=&kind=&limit=` | RFC3339 times; defaults to the last 24h | | GET | `/api/v1/summary/daily?date=YYYY-MM-DD` | totals per label and kind, plus goal results | | GET | `/healthz`, `/readyz` | no auth | +| GET | `/` | dashboard page; enter any API key to view a day's goals, totals and timeline | The event batch format is shared by all `*/events` endpoints. A batch holds at most 1000 events. diff --git a/internal/api/api.go b/internal/api/api.go index b1fe302..964a636 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -14,6 +14,7 @@ import ( "ccp/internal/ingest" "ccp/internal/store" "ccp/internal/summary" + "ccp/internal/web" ) const ( @@ -36,6 +37,7 @@ func New(s *store.Store, loc *time.Location, log *slog.Logger) http.Handler { writeJSON(w, http.StatusOK, map[string]string{"status": "ok"}) }) mux.HandleFunc("GET /readyz", srv.ready) + mux.HandleFunc("GET /{$}", web.Handler) api := http.NewServeMux() api.HandleFunc("POST /desktop/events", srv.ingestEvents(ingest.Desktop)) diff --git a/internal/web/index.html b/internal/web/index.html new file mode 100644 index 0000000..816de21 --- /dev/null +++ b/internal/web/index.html @@ -0,0 +1,164 @@ + + + + + +Activity Tracker + + + +
+
+

Activity Tracker

+ +
+ + + +

+ +
+ + + diff --git a/internal/web/web.go b/internal/web/web.go new file mode 100644 index 0000000..187529f --- /dev/null +++ b/internal/web/web.go @@ -0,0 +1,16 @@ +// Package web serves the dashboard, a single static page that reads the +// /api/v1 query endpoints with an API key the viewer enters. +package web + +import ( + _ "embed" + "net/http" +) + +//go:embed index.html +var index []byte + +func Handler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/html; charset=utf-8") + w.Write(index) +}