From b6b345d7dc956685d37a849a8d09bb1638434cf7 Mon Sep 17 00:00:00 2001 From: Bryce Fisher-Fleig Date: Wed, 1 May 2024 17:26:42 -0700 Subject: [PATCH] feat: add HOST config to control which network interface ld-relay binds to --- config/config.go | 1 + internal/application/server.go | 3 ++- ld-relay.go | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 9118ac41..8c931d3f 100644 --- a/config/config.go +++ b/config/config.go @@ -133,6 +133,7 @@ type MainConfig struct { StreamURI ct.OptURLAbsolute `conf:"STREAM_URI"` BaseURI ct.OptURLAbsolute `conf:"BASE_URI"` ClientSideBaseURI ct.OptURLAbsolute `conf:"CLIENT_SIDE_BASE_URI"` + Host string `conf:"HOST"` Port ct.OptIntGreaterThanZero `conf:"PORT"` InitTimeout ct.OptDuration `conf:"INIT_TIMEOUT"` HeartbeatInterval ct.OptDuration `conf:"HEARTBEAT_INTERVAL"` diff --git a/internal/application/server.go b/internal/application/server.go index 7c4a3d8c..63f668aa 100644 --- a/internal/application/server.go +++ b/internal/application/server.go @@ -14,6 +14,7 @@ import ( // StartHTTPServer starts the server, with or without TLS. It returns immediately, starting the server // on a separate goroutine; if the server fails to start up, it sends an error to the error channel. func StartHTTPServer( + host string, port int, handler http.Handler, tlsEnabled bool, @@ -22,7 +23,7 @@ func StartHTTPServer( loggers ldlog.Loggers, ) (*http.Server, <-chan error) { srv := &http.Server{ - Addr: fmt.Sprintf(":%d", port), + Addr: fmt.Sprintf("%s:%d", host, port), Handler: handler, ReadHeaderTimeout: 10 * time.Second, } diff --git a/ld-relay.go b/ld-relay.go index d5433237..97e3c126 100644 --- a/ld-relay.go +++ b/ld-relay.go @@ -60,8 +60,10 @@ func main() { } port := c.Main.Port.GetOrElse(config.DefaultPort) + host := c.Main.Host _, errs := application.StartHTTPServer( + host, port, r, c.Main.TLSEnabled,