diff options
| author | bndw <ben@bdw.to> | 2026-02-13 20:50:27 -0800 |
|---|---|---|
| committer | bndw <ben@bdw.to> | 2026-02-13 20:50:27 -0800 |
| commit | 97e6c9a0c2c32bf514d3a4218d239741f1dc26c8 (patch) | |
| tree | 259cc3a149c9521adb9d212d0f4e5261a1ed08c6 /internal/handler/websocket/handler.go | |
| parent | dfa19ff0776be0850ad7b86ca579601431349593 (diff) | |
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
Diffstat (limited to 'internal/handler/websocket/handler.go')
| -rw-r--r-- | internal/handler/websocket/handler.go | 28 |
1 files changed, 24 insertions, 4 deletions
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 { | |||
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | type Handler struct { | 23 | type Handler struct { |
| 24 | store EventStore | 24 | store EventStore |
| 25 | subs *subscription.Manager | 25 | subs *subscription.Manager |
| 26 | indexData IndexData | ||
| 26 | } | 27 | } |
| 27 | 28 | ||
| 28 | func NewHandler(store EventStore, subs *subscription.Manager) *Handler { | 29 | func NewHandler(store EventStore, subs *subscription.Manager) *Handler { |
| @@ -32,9 +33,28 @@ func NewHandler(store EventStore, subs *subscription.Manager) *Handler { | |||
| 32 | } | 33 | } |
| 33 | } | 34 | } |
| 34 | 35 | ||
| 36 | // SetIndexData sets the addresses for the index page | ||
| 37 | func (h *Handler) SetIndexData(grpcAddr, httpAddr, wsAddr string) { | ||
| 38 | h.indexData = IndexData{ | ||
| 39 | GrpcAddr: grpcAddr, | ||
| 40 | HttpAddr: httpAddr, | ||
| 41 | WsAddr: wsAddr, | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 35 | func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | 45 | func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| 36 | if r.Method == "GET" && r.Header.Get("Accept") == "application/nostr+json" { | 46 | // Handle GET requests |
| 37 | h.ServeNIP11(w, r) | 47 | if r.Method == "GET" { |
| 48 | accept := r.Header.Get("Accept") | ||
| 49 | |||
| 50 | // NIP-11: Relay information document | ||
| 51 | if accept == "application/nostr+json" { | ||
| 52 | h.ServeNIP11(w, r) | ||
| 53 | return | ||
| 54 | } | ||
| 55 | |||
| 56 | // Serve HTML index for browsers | ||
| 57 | h.ServeIndex(w, r, h.indexData) | ||
| 38 | return | 58 | return |
| 39 | } | 59 | } |
| 40 | 60 | ||
