From 95cadb937da10c1f9271f49c1584a2cd5ede820b Mon Sep 17 00:00:00 2001 From: lenny Date: Tue, 30 Mar 2021 14:24:00 -0700 Subject: [PATCH] fix: Fix webserver to use ServerBindAddr only is not blank as rest of EdgeX Services closes #775 BREAKING CHANGE: Webserver will be locked down to listen just to `Host` value when If `ServerBindAddr ` is blank Signed-off-by: lenny --- app-service-template/res/configuration.toml | 1 + go.mod | 6 +++++- internal/webserver/server.go | 12 ++++++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app-service-template/res/configuration.toml b/app-service-template/res/configuration.toml index 4d7af84bc..720406693 100644 --- a/app-service-template/res/configuration.toml +++ b/app-service-template/res/configuration.toml @@ -21,6 +21,7 @@ BootTimeout = '30s' ClientMonitor = '15s' CheckInterval = '10s' Host = 'localhost' +ServerBindAddr = '' # Leave blank so default to Host value unless different value is needed. Port = 49600 # TODO: set this port appropriately Protocol = 'http' ReadMaxLimit = 100 diff --git a/go.mod b/go.mod index 1f2ad3bf0..7598bc404 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( bitbucket.org/bertimus9/systemstat v0.0.0-20180207000608-0eeff89b0690 github.com/diegoholiveira/jsonlogic v1.0.1-0.20200220175622-ab7989be08b9 github.com/eclipse/paho.mqtt.golang v1.3.2 - github.com/edgexfoundry/go-mod-bootstrap/v2 v2.0.0-dev.27 + github.com/edgexfoundry/go-mod-bootstrap/v2 v2.0.0-dev.28 github.com/edgexfoundry/go-mod-core-contracts/v2 v2.0.0-dev.62 github.com/edgexfoundry/go-mod-messaging/v2 v2.0.0-dev.7 github.com/edgexfoundry/go-mod-registry/v2 v2.0.0-dev.4 @@ -16,3 +16,7 @@ require ( github.com/gorilla/mux v1.8.0 github.com/stretchr/testify v1.7.0 ) + +replace ( + github.com/edgexfoundry/go-mod-bootstrap/v2 => ../MODS/go-mod-bootstrap +) diff --git a/internal/webserver/server.go b/internal/webserver/server.go index ae82f1de3..3460be96b 100644 --- a/internal/webserver/server.go +++ b/internal/webserver/server.go @@ -105,10 +105,14 @@ func (webserver *WebServer) StartWebServer(errChannel chan error) { // Helper function to handle HTTPs or HTTP connection based on the configured protocol func listenAndServe(webserver *WebServer, serviceTimeout time.Duration, errChannel chan error) { - - // this allows env overrides to explicitly set the value used - // for ListenAndServe, as needed for different deployments - addr := fmt.Sprintf("%v:%d", webserver.config.Service.ServerBindAddr, webserver.config.Service.Port) + // Th Host value is the default bind address value if the ServerBindAddr value is not specified + // this allows env overrides to explicitly set the value used for ListenAndServe, + // as needed for different deployments + bindAddress := webserver.config.Service.Host + if len(webserver.config.Service.ServerBindAddr) != 0 { + bindAddress = webserver.config.Service.ServerBindAddr + } + addr := fmt.Sprintf("%s:%d", bindAddress, webserver.config.Service.Port) if webserver.config.Service.Protocol == "https" { webserver.lc.Infof("Starting HTTPS Web Server on address %v", addr)