diff options
author | Steve Manuel <nilslice@gmail.com> | 2017-07-23 10:15:12 -0600 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2017-07-23 10:15:12 -0600 |
commit | 9ea0ec0e6fa0bd65c8d263a1cd418f83a3848a8b (patch) | |
tree | 92d30a45e38369bce7c9666c414657405fdacc8e /cmd | |
parent | 271bae22b9c954d76e96712a44fe4702f356d116 (diff) |
adding bind option in CLI run cmd, including in system config
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/ponzu/main.go | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/cmd/ponzu/main.go b/cmd/ponzu/main.go index 72f0abf..8d293e8 100644 --- a/cmd/ponzu/main.go +++ b/cmd/ponzu/main.go @@ -26,6 +26,7 @@ import ( ) var ( + bind string httpsport int port int docsport int @@ -103,6 +104,7 @@ $ ponzu run --port=8888 api`, serve := exec.Command(buildPathName, "serve", services, + fmt.Sprintf("--bind=%s", bind), fmt.Sprintf("--port=%d", port), fmt.Sprintf("--https-port=%d", httpsport), fmt.Sprintf("--docs-port=%d", docsport), @@ -187,15 +189,23 @@ var serveCmd = &cobra.Command{ log.Fatalln("System failed to save config. Please try to run again.", err) } - fmt.Printf("Server listening on :%d for HTTP requests...\n", port) - fmt.Println("\nvisit `/admin` to get started.") - log.Fatalln(http.ListenAndServe(fmt.Sprintf(":%d", port), nil)) + // save the bound address the system is listening on so internal system can make + // HTTP api calls while in dev or production w/o adding more cli flags + err = db.PutConfig("bind_addr", bind) + if err != nil { + log.Fatalln("System failed to save config. Please try to run again.", err) + } + + fmt.Printf("Server listening at %s:%d for HTTP requests...\n", bind, port) + fmt.Println("\nVisit '/admin' to get started.") + log.Fatalln(http.ListenAndServe(fmt.Sprintf("%s:%d", bind, port), nil)) return nil }, } func init() { for _, cmd := range []*cobra.Command{runCmd, serveCmd} { + cmd.Flags().StringVar(&bind, "bind", "localhost", "address for ponzu to bind the HTTP(S) server") cmd.Flags().IntVar(&httpsport, "https-port", 443, "port for ponzu to bind its HTTPS listener") cmd.Flags().IntVar(&port, "port", 8080, "port for ponzu to bind its HTTP listener") cmd.Flags().IntVar(&docsport, "docs-port", 1234, "[dev environment] override the documentation server port") |