From 97e6c9a0c2c32bf514d3a4218d239741f1dc26c8 Mon Sep 17 00:00:00 2001 From: bndw Date: Fri, 13 Feb 2026 20:50:27 -0800 Subject: feat: add HTML index page for browser viewing Add a beautiful HTML landing page when visiting relay in browser: - Shows all three protocol endpoints (gRPC, Connect, WebSocket) - Lists supported NIPs (01, 09, 11) - Displays relay features and info - Responsive design with gradient styling - Serves on GET requests (regular Accept header) - NIP-11 still served for Accept: application/nostr+json --- internal/handler/websocket/handler.go | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'internal/handler/websocket/handler.go') diff --git a/internal/handler/websocket/handler.go b/internal/handler/websocket/handler.go index 224a2f8..2d531e9 100644 --- a/internal/handler/websocket/handler.go +++ b/internal/handler/websocket/handler.go @@ -21,8 +21,9 @@ type EventStore interface { } type Handler struct { - store EventStore - subs *subscription.Manager + store EventStore + subs *subscription.Manager + indexData IndexData } func NewHandler(store EventStore, subs *subscription.Manager) *Handler { @@ -32,9 +33,28 @@ func NewHandler(store EventStore, subs *subscription.Manager) *Handler { } } +// SetIndexData sets the addresses for the index page +func (h *Handler) SetIndexData(grpcAddr, httpAddr, wsAddr string) { + h.indexData = IndexData{ + GrpcAddr: grpcAddr, + HttpAddr: httpAddr, + WsAddr: wsAddr, + } +} + func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if r.Method == "GET" && r.Header.Get("Accept") == "application/nostr+json" { - h.ServeNIP11(w, r) + // Handle GET requests + if r.Method == "GET" { + accept := r.Header.Get("Accept") + + // NIP-11: Relay information document + if accept == "application/nostr+json" { + h.ServeNIP11(w, r) + return + } + + // Serve HTML index for browsers + h.ServeIndex(w, r, h.indexData) return } -- cgit v1.2.3