Skip to content

Commit

Permalink
Allow change the server bind address
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcnunes committed Nov 11, 2016
1 parent 331df14 commit 6c4af14
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ import (
// version is definded during the build
var version string

func getServiceAddress() string {
if env := os.Getenv("VIRTUAL_PORT"); env != "" {
return ":" + env
}

if env := os.Getenv("HTTP_PORT"); env != "" {
return ":" + env
}

return ":3000"
}

func handleSubmit(w http.ResponseWriter, r *http.Request, defaults []string) {
var d struct{ Args []string }

Expand Down Expand Up @@ -62,6 +74,7 @@ func main() {
http.NotFound(w, r)
})

log.Println("Starting server")
log.Fatal(http.ListenAndServe(":8080", nil))
addrs := getServiceAddress()
log.Printf("Starting server at %s\n", addrs)
log.Fatal(http.ListenAndServe(addrs, nil))
}

0 comments on commit 6c4af14

Please sign in to comment.