From 3b78c9db208e2a03b72c42af1e86f44c4be7e884 Mon Sep 17 00:00:00 2001 From: Sargun Dhillon Date: Tue, 22 May 2018 16:27:31 -0700 Subject: [PATCH 1/2] Add mechanism to specify listening host This makes it so you can listen on a specific IP / hostname. --- main.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 3c462bd..d5a7003 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "fmt" "io" "log" + "net" "net/http" "os" "reflect" @@ -36,6 +37,7 @@ type config struct { basicAuthUser string // BASIC_AUTH_USER basicAuthPass string // BASIC_AUTH_PASS port string // APP_PORT + host string // APP_HOST accessLog bool // ACCESS_LOG sslCert string // SSL_CERT_PATH sslKey string // SSL_KEY_PATH @@ -73,11 +75,12 @@ func main() { }) // Listen & Serve - log.Printf("[service] listening on port %s", c.port) + addr := net.JoinHostPort(c.host, c.port) + log.Printf("[service] listening on %s", addr) if (len(c.sslCert) > 0) && (len(c.sslKey) > 0) { - log.Fatal(http.ListenAndServeTLS(":"+c.port, c.sslCert, c.sslKey, nil)) + log.Fatal(http.ListenAndServeTLS(addr, c.sslCert, c.sslKey, nil)) } else { - log.Fatal(http.ListenAndServe(":"+c.port, nil)) + log.Fatal(http.ListenAndServe(addr, nil)) } } @@ -140,6 +143,7 @@ func configFromEnvironmentVariables() *config { basicAuthUser: os.Getenv("BASIC_AUTH_USER"), basicAuthPass: os.Getenv("BASIC_AUTH_PASS"), port: port, + host: os.Getenv("APP_HOST"), accessLog: accessLog, sslCert: os.Getenv("SSL_CERT_PATH"), sslKey: os.Getenv("SSL_KEY_PATH"), From bbd0ad82914291f33685419ef8c055d8a1a4d365 Mon Sep 17 00:00:00 2001 From: Sargun Dhillon Date: Tue, 22 May 2018 16:29:45 -0700 Subject: [PATCH 2/2] Document APP_HOST --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 18b0255..8c75bf9 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ CORS_ALLOW_METHODS | CORS: Comma-delimited list of the allowed [HTTP requ CORS_ALLOW_HEADERS | CORS: Comma-delimited list of the supported request headers. | | - CORS_MAX_AGE | CORS: Maximum number of seconds the results of a preflight request can be cached. | | 600 APP_PORT | The port number to be assigned for listening. | | 80 +APP_HOST | The host name used to the listener | | Listens on all available unicast and anycast IP addresses of the local system. ACCESS_LOG | Send access logs to /dev/stdout. | | false STRIP_PATH | Strip path prefix. | | - CONTENT_ENCODING | Compress response data if the request allows. | | false