gRPC-web proxy (#8077)
* init * WIP config * WIP add proxy server * fmt * WIP * setup proxy server * clean go.mod * lint * lint * lint * custom codec * lint * add comments * change grpc-proxy port * add grpc-web * update server/start.go * add tests * add test with client * Update server/start.go Co-authored-by: Anil Kumar Kammari <anil@vitwit.com> * Update server/start.go Co-authored-by: Amaury <amaury.martiny@protonmail.com> * Update server/start.go Co-authored-by: Amaury <amaury.martiny@protonmail.com> * review changes * review changes * Update server/start.go Co-authored-by: Anil Kumar Kammari <anil@vitwit.com> Co-authored-by: Amaury <amaury.martiny@protonmail.com> Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Anil Kumar Kammari
Amaury
Aleksandr Bezobchuk
mergify[bot]
parent
01eec66d28
commit
b771effc6c
@@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -157,9 +158,10 @@ type (
|
||||
ValAddress sdk.ValAddress
|
||||
RPCClient tmclient.Client
|
||||
|
||||
tmNode *node.Node
|
||||
api *api.Server
|
||||
grpc *grpc.Server
|
||||
tmNode *node.Node
|
||||
api *api.Server
|
||||
grpc *grpc.Server
|
||||
grpcWeb *http.Server
|
||||
}
|
||||
)
|
||||
|
||||
@@ -212,6 +214,7 @@ func New(t *testing.T, cfg Config) *Network {
|
||||
apiAddr := ""
|
||||
tmCfg.RPC.ListenAddress = ""
|
||||
appCfg.GRPC.Enable = false
|
||||
appCfg.GRPCWeb.Enable = false
|
||||
if i == 0 {
|
||||
apiListenAddr, _, err := server.FreeTCPAddr()
|
||||
require.NoError(t, err)
|
||||
@@ -229,6 +232,11 @@ func New(t *testing.T, cfg Config) *Network {
|
||||
require.NoError(t, err)
|
||||
appCfg.GRPC.Address = fmt.Sprintf("0.0.0.0:%s", grpcPort)
|
||||
appCfg.GRPC.Enable = true
|
||||
|
||||
_, grpcWebPort, err := server.FreeTCPAddr()
|
||||
require.NoError(t, err)
|
||||
appCfg.GRPCWeb.Address = fmt.Sprintf("0.0.0.0:%s", grpcWebPort)
|
||||
appCfg.GRPCWeb.Enable = true
|
||||
}
|
||||
|
||||
logger := log.NewNopLogger()
|
||||
@@ -466,6 +474,9 @@ func (n *Network) Cleanup() {
|
||||
|
||||
if v.grpc != nil {
|
||||
v.grpc.Stop()
|
||||
if v.grpcWeb != nil {
|
||||
_ = v.grpcWeb.Close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,6 +99,24 @@ func startInProcess(cfg Config, val *Validator) error {
|
||||
}
|
||||
|
||||
val.grpc = grpcSrv
|
||||
|
||||
if val.AppConfig.GRPCWeb.Enable {
|
||||
errCh1 := make(chan error)
|
||||
go func() {
|
||||
grpcWeb, err := servergrpc.StartGRPCWeb(grpcSrv, *val.AppConfig)
|
||||
if err != nil {
|
||||
errCh1 <- err
|
||||
}
|
||||
|
||||
val.grpcWeb = grpcWeb
|
||||
}()
|
||||
select {
|
||||
case err := <-errCh1:
|
||||
return err
|
||||
case <-time.After(5 * time.Second): // assume server started successfully
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user