From 82650d00aeee5ad01822cf9c6be987c0dae830fe Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Sat, 29 Feb 2020 09:20:24 -0500 Subject: [PATCH] Support setting server port with PORT env var This also logs the address the application is serving on. --- cmd/cdr/generate.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/cdr/generate.go b/cmd/cdr/generate.go index f59d668..6cf57ac 100644 --- a/cmd/cdr/generate.go +++ b/cmd/cdr/generate.go @@ -92,5 +92,10 @@ func serveAction(c *cli.Context) error { log.Printf("GET /") }) - return http.ListenAndServe(":9991", nil) + port := os.Getenv("PORT") + if port == "" { + port = "9991" + } + log.Printf("Serving on http://localhost:%s", port) + return http.ListenAndServe(":"+port, nil) }