Skip to content

Commit

Permalink
Support specific host for duplex server (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
pdeslaur authored May 6, 2023
1 parent 6a4adb3 commit 6005601
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/duplex/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Duplex struct {
Server *grpc.Server
MUX *runtime.ServeMux
Loopback string
Host string
Port int
DialOptions []grpc.DialOption
}
Expand Down Expand Up @@ -101,7 +102,7 @@ func (d *Duplex) RegisterHandler(ctx context.Context, fn RegisterHandlerFromEndp
// Note: This call is blocking.
func (d *Duplex) ListenAndServe(_ context.Context) error {
server := &http.Server{
Addr: fmt.Sprintf(":%d", d.Port),
Addr: fmt.Sprintf("%s:%d", d.Host, d.Port),
Handler: grpcHandlerFunc(d.Server, d.MUX),
ReadHeaderTimeout: 600 * time.Second,
}
Expand All @@ -120,5 +121,5 @@ func (d *Duplex) Serve(_ context.Context, listener net.Listener) error {
// /metrics endpoint for exporting Prometheus metrics in the background.
// Call this *after* all services have been registered.
func (d *Duplex) RegisterListenAndServeMetrics(port int, enablePprof bool) {
metrics.RegisterListenAndServe(d.Server, fmt.Sprintf(":%d", port), enablePprof)
metrics.RegisterListenAndServe(d.Server, fmt.Sprintf("%s:%d", d.Host, port), enablePprof)
}

0 comments on commit 6005601

Please sign in to comment.