Skip to content

Commit

Permalink
fix: Fix webserver to use ServerBindAddr only is not blank as rest of…
Browse files Browse the repository at this point in the history
… 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 <[email protected]>
  • Loading branch information
lenny committed Mar 30, 2021
1 parent 60c5fe5 commit ef21f22
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions app-service-template/res/configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
12 changes: 8 additions & 4 deletions internal/webserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
// The 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)
Expand Down

0 comments on commit ef21f22

Please sign in to comment.