Replace --webPort and --tlsPort with a single --addr option.

This commit is contained in:
David Fifield 2017-07-14 20:29:02 -07:00
parent 2d89aa0b7b
commit afe7716903
2 changed files with 6 additions and 9 deletions

View file

@ -42,9 +42,7 @@ without having to run as root:
``` ```
setcap 'cap_net_bind_service=+ep' /usr/local/bin/broker setcap 'cap_net_bind_service=+ep' /usr/local/bin/broker
``` ```
You can control the listening port with the --tlsPort You can control the listening port with the --addr option.
or --webPort options (--webPort is honored only when
also using --disable-tls).
You'll need to provide the URL of the custom broker You'll need to provide the URL of the custom broker
to the client plugin using the `--url $URL` flag. to the client plugin using the `--url $URL` flag.

View file

@ -234,14 +234,13 @@ func ipHandler(w http.ResponseWriter, r *http.Request) {
func main() { func main() {
var acmeEmail string var acmeEmail string
var acmeHostnamesCommas string var acmeHostnamesCommas string
var addr string
var disableTLS bool var disableTLS bool
var http_port, https_port string
flag.StringVar(&acmeEmail, "acme-email", "", "optional contact email for Let's Encrypt notifications") flag.StringVar(&acmeEmail, "acme-email", "", "optional contact email for Let's Encrypt notifications")
flag.StringVar(&acmeHostnamesCommas, "acme-hostnames", "", "comma-separated hostnames for TLS certificate") flag.StringVar(&acmeHostnamesCommas, "acme-hostnames", "", "comma-separated hostnames for TLS certificate")
flag.StringVar(&addr, "addr", ":443", "address to listen on")
flag.BoolVar(&disableTLS, "disable-tls", false, "don't use HTTPS") flag.BoolVar(&disableTLS, "disable-tls", false, "don't use HTTPS")
flag.StringVar(&http_port, "webPort", "80", "HTTP port number")
flag.StringVar(&https_port, "tlsPort", "443", "HTTPS port number")
flag.Parse() flag.Parse()
ctx := NewBrokerContext() ctx := NewBrokerContext()
@ -257,7 +256,9 @@ func main() {
http.Handle("/debug", SnowflakeHandler{ctx, debugHandler}) http.Handle("/debug", SnowflakeHandler{ctx, debugHandler})
var err error var err error
var server http.Server server := http.Server{
Addr: addr,
}
if acmeHostnamesCommas != "" { if acmeHostnamesCommas != "" {
acmeHostnames := strings.Split(acmeHostnamesCommas, ",") acmeHostnames := strings.Split(acmeHostnamesCommas, ",")
@ -269,11 +270,9 @@ func main() {
Email: acmeEmail, Email: acmeEmail,
} }
server.Addr = net.JoinHostPort("", https_port)
server.TLSConfig = &tls.Config{GetCertificate: certManager.GetCertificate} server.TLSConfig = &tls.Config{GetCertificate: certManager.GetCertificate}
err = server.ListenAndServeTLS("", "") err = server.ListenAndServeTLS("", "")
} else if disableTLS { } else if disableTLS {
server.Addr = net.JoinHostPort("", http_port)
err = server.ListenAndServe() err = server.ListenAndServe()
} else { } else {
log.Fatal("the --acme-hostnames or --disable-tls option is required") log.Fatal("the --acme-hostnames or --disable-tls option is required")