diff --git a/server/v2/api/grpcgateway/server.go b/server/v2/api/grpcgateway/server.go index 16a622a94961..977eb369c894 100644 --- a/server/v2/api/grpcgateway/server.go +++ b/server/v2/api/grpcgateway/server.go @@ -75,7 +75,13 @@ func New[T transaction.Tx]( s.logger = logger.With(log.ModuleKey, s.Name()) s.config = serverCfg + mux := http.NewServeMux() + mux.Handle("/", s.GRPCGatewayRouter) + s.server = &http.Server{ + Addr: s.config.Address, + Handler: mux, + } return s, nil } @@ -110,14 +116,6 @@ func (s *Server[T]) Start(ctx context.Context) error { return nil } - mux := http.NewServeMux() - mux.Handle("/", s.GRPCGatewayRouter) - - s.server = &http.Server{ - Addr: s.config.Address, - Handler: mux, - } - s.logger.Info("starting gRPC-Gateway server...", "address", s.config.Address) if err := s.server.ListenAndServe(); err != nil && err != http.ErrServerClosed { return fmt.Errorf("failed to start gRPC-Gateway server: %w", err) diff --git a/server/v2/api/rest/server.go b/server/v2/api/rest/server.go index 5cffaa282f69..1ea098c6dce0 100644 --- a/server/v2/api/rest/server.go +++ b/server/v2/api/rest/server.go @@ -46,7 +46,10 @@ func New[T transaction.Tx]( } } srv.config = serverCfg - + srv.httpServer = &http.Server{ + Addr: srv.config.Address, + Handler: srv.router, + } return srv, nil } @@ -69,11 +72,6 @@ func (s *Server[T]) Start(ctx context.Context) error { return nil } - s.httpServer = &http.Server{ - Addr: s.config.Address, - Handler: s.router, - } - s.logger.Info("starting HTTP server", "address", s.config.Address) if err := s.httpServer.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { s.logger.Error("failed to start HTTP server", "error", err) diff --git a/server/v2/api/telemetry/server.go b/server/v2/api/telemetry/server.go index f612964a8476..1236f9112ba0 100644 --- a/server/v2/api/telemetry/server.go +++ b/server/v2/api/telemetry/server.go @@ -52,6 +52,17 @@ func New[T transaction.Tx](cfg server.ConfigMap, logger log.Logger, enableTeleme return nil, fmt.Errorf("failed to initialize metrics: %w", err) } srv.metrics = metrics + mux := http.NewServeMux() + // /metrics is the default standard path for Prometheus metrics. + mux.HandleFunc("/metrics", srv.metricsHandler) + mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, "/metrics", http.StatusMovedPermanently) + }) + + srv.server = &http.Server{ + Addr: srv.config.Address, + Handler: mux, + } return srv, nil } @@ -74,18 +85,6 @@ func (s *Server[T]) Start(ctx context.Context) error { return nil } - mux := http.NewServeMux() - // /metrics is the default standard path for Prometheus metrics. - mux.HandleFunc("/metrics", s.metricsHandler) - mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - http.Redirect(w, r, "/metrics", http.StatusMovedPermanently) - }) - - s.server = &http.Server{ - Addr: s.config.Address, - Handler: mux, - } - s.logger.Info("starting telemetry server...", "address", s.config.Address) if err := s.server.ListenAndServe(); err != nil && err != http.ErrServerClosed { return fmt.Errorf("failed to start telemetry server: %w", err) diff --git a/systemtests/system.go b/systemtests/system.go index 5b964ee03327..fa39beb4d509 100644 --- a/systemtests/system.go +++ b/systemtests/system.go @@ -735,6 +735,7 @@ func (s *SystemUnderTest) AddFullnode(t *testing.T, beforeStart ...func(nodeNumb if tomlFile == "app.toml" && IsV2() { file := filepath.Join(WorkDir, s.nodePath(nodeNumber), "config", tomlFile) EditToml(file, func(doc *tomledit.Document) { + SetValue(doc, fmt.Sprintf("%s:%d", node.IP, DefaultApiPort+nodeNumber), "grpc-gateway", "address") SetValue(doc, fmt.Sprintf("%s:%d", node.IP, DefaultRestPort+nodeNumber), "rest", "address") }) }