Skip to content

Commit

Permalink
Merge pull request #16 from sargun/bind-ip
Browse files Browse the repository at this point in the history
Bind ip
  • Loading branch information
pottava authored May 23, 2018
2 parents efea189 + bbd0ad8 commit 900e99a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"io"
"log"
"net"
"net/http"
"os"
"reflect"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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"),
Expand Down

0 comments on commit 900e99a

Please sign in to comment.