diff options
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 | ||
