Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix webserver to use ServerBindAddr only if not blank as rest of EdgeX #776

Merged
merged 1 commit into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 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 Down
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