Skip to content

Commit 900e99a

Browse files
authored
Merge pull request #16 from sargun/bind-ip
Bind ip
2 parents efea189 + bbd0ad8 commit 900e99a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ CORS_ALLOW_METHODS | CORS: Comma-delimited list of the allowed [HTTP requ
4545
CORS_ALLOW_HEADERS | CORS: Comma-delimited list of the supported request headers. | | -
4646
CORS_MAX_AGE | CORS: Maximum number of seconds the results of a preflight request can be cached. | | 600
4747
APP_PORT | The port number to be assigned for listening. | | 80
48+
APP_HOST | The host name used to the listener | | Listens on all available unicast and anycast IP addresses of the local system.
4849
ACCESS_LOG | Send access logs to /dev/stdout. | | false
4950
STRIP_PATH | Strip path prefix. | | -
5051
CONTENT_ENCODING | Compress response data if the request allows. | | false

main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"io"
1010
"log"
11+
"net"
1112
"net/http"
1213
"os"
1314
"reflect"
@@ -36,6 +37,7 @@ type config struct {
3637
basicAuthUser string // BASIC_AUTH_USER
3738
basicAuthPass string // BASIC_AUTH_PASS
3839
port string // APP_PORT
40+
host string // APP_HOST
3941
accessLog bool // ACCESS_LOG
4042
sslCert string // SSL_CERT_PATH
4143
sslKey string // SSL_KEY_PATH
@@ -73,11 +75,12 @@ func main() {
7375
})
7476

7577
// Listen & Serve
76-
log.Printf("[service] listening on port %s", c.port)
78+
addr := net.JoinHostPort(c.host, c.port)
79+
log.Printf("[service] listening on %s", addr)
7780
if (len(c.sslCert) > 0) && (len(c.sslKey) > 0) {
78-
log.Fatal(http.ListenAndServeTLS(":"+c.port, c.sslCert, c.sslKey, nil))
81+
log.Fatal(http.ListenAndServeTLS(addr, c.sslCert, c.sslKey, nil))
7982
} else {
80-
log.Fatal(http.ListenAndServe(":"+c.port, nil))
83+
log.Fatal(http.ListenAndServe(addr, nil))
8184
}
8285
}
8386

@@ -140,6 +143,7 @@ func configFromEnvironmentVariables() *config {
140143
basicAuthUser: os.Getenv("BASIC_AUTH_USER"),
141144
basicAuthPass: os.Getenv("BASIC_AUTH_PASS"),
142145
port: port,
146+
host: os.Getenv("APP_HOST"),
143147
accessLog: accessLog,
144148
sslCert: os.Getenv("SSL_CERT_PATH"),
145149
sslKey: os.Getenv("SSL_KEY_PATH"),

0 commit comments

Comments
 (0)