From 83876eae868bd1e4fb6b9a823a6e8173919f290d Mon Sep 17 00:00:00 2001 From: bndw Date: Fri, 13 Feb 2026 18:26:53 -0800 Subject: feat: add Connect (gRPC over HTTP/JSON) support Connect integration: - Buf Connect codegen added to buf.gen.yaml - Connect handler wraps gRPC server - Serves on same port as WebSocket (:8080) - HTTP/2 with h2c for cleartext HTTP/2 Now serving THREE protocols: 1. gRPC (native) on :50051 - binary, high performance 2. Connect on :8080/nostr.v1.NostrRelay/* - HTTP/JSON, browser compatible 3. WebSocket on :8080/ - Nostr standard protocol All three protocols share: - Same storage layer - Same subscription manager - Same validation logic Browser-friendly! Call gRPC methods with fetch() or curl. --- cmd/relay/main.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'cmd') diff --git a/cmd/relay/main.go b/cmd/relay/main.go index 53296b9..9cf6ad6 100644 --- a/cmd/relay/main.go +++ b/cmd/relay/main.go @@ -11,9 +11,14 @@ import ( "context" + "connectrpc.com/connect" + "golang.org/x/net/http2" + "golang.org/x/net/http2/h2c" "google.golang.org/grpc" pb "northwest.io/nostr-grpc/api/nostr/v1" + "northwest.io/nostr-grpc/api/nostr/v1/nostrv1connect" + connecthandler "northwest.io/nostr-grpc/internal/handler/connect" grpchandler "northwest.io/nostr-grpc/internal/handler/grpc" wshandler "northwest.io/nostr-grpc/internal/handler/websocket" "northwest.io/nostr-grpc/internal/storage" @@ -39,7 +44,14 @@ func main() { grpcHandler := grpchandler.NewServer(store) grpcHandler.SetSubscriptionManager(subManager) + connectHandler := connecthandler.NewHandler(grpcHandler) + + mux := http.NewServeMux() + path, handler := nostrv1connect.NewNostrRelayHandler(connectHandler, connect.WithInterceptors()) + mux.Handle(path, handler) + wsHandler := wshandler.NewHandler(store, subManager) + mux.Handle("/", wsHandler) grpcLis, err := net.Listen("tcp", *grpcAddr) if err != nil { @@ -51,11 +63,13 @@ func main() { httpServer := &http.Server{ Addr: *wsAddr, - Handler: wsHandler, + Handler: h2c.NewHandler(mux, &http2.Server{}), } log.Printf("gRPC server listening on %s", *grpcAddr) - log.Printf("WebSocket server listening on %s", *wsAddr) + log.Printf("HTTP server listening on %s", *wsAddr) + log.Printf(" - Connect (gRPC-Web) at %s/nostr.v1.NostrRelay/*", *wsAddr) + log.Printf(" - WebSocket (Nostr) at %s/", *wsAddr) log.Printf("Database: %s", *dbPath) sigChan := make(chan os.Signal, 1) -- cgit v1.2.3