From 45b7e8c23c6cd10ba35c8fe85b2dcfc0c635194a Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 17 Oct 2022 13:07:19 -0700 Subject: [PATCH] cmd/tailscale: make tailscale cert --serve-demo accept optional listen argument Change-Id: I48f2f4f74c9996b9ed4bee02c61f125d42154a34 Signed-off-by: Brad Fitzpatrick --- cmd/tailscale/cli/cert.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/tailscale/cli/cert.go b/cmd/tailscale/cli/cert.go index 0c59d4c74..ba4679378 100644 --- a/cmd/tailscale/cli/cert.go +++ b/cmd/tailscale/cli/cert.go @@ -8,6 +8,7 @@ "bytes" "context" "crypto/tls" + "errors" "flag" "fmt" "log" @@ -44,6 +45,7 @@ func runCert(ctx context.Context, args []string) error { if certArgs.serve { s := &http.Server{ + Addr: ":443", TLSConfig: &tls.Config{ GetCertificate: localClient.GetCertificate, }, @@ -57,7 +59,16 @@ func runCert(ctx context.Context, args []string) error { fmt.Fprintf(w, "

Hello from Tailscale

It works.") }), } - log.Printf("running TLS server on :443 ...") + switch len(args) { + case 0: + // Nothing. + case 1: + s.Addr = args[0] + default: + return errors.New("too many arguments; max 1 allowed with --serve-demo (the listen address)") + } + + log.Printf("running TLS server on %s ...", s.Addr) return s.ListenAndServeTLS("", "") }