From 9ea0ec0e6fa0bd65c8d263a1cd418f83a3848a8b Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Sun, 23 Jul 2017 10:15:12 -0600 Subject: adding bind option in CLI run cmd, including in system config --- cmd/ponzu/main.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'cmd') 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") -- cgit v1.2.3 From f48dee852520bde5f7984bc2e010483518a9ce2a Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Sun, 23 Jul 2017 10:20:33 -0600 Subject: add default override for bind address --- cmd/ponzu/main.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/ponzu/main.go b/cmd/ponzu/main.go index 8d293e8..fd64efc 100644 --- a/cmd/ponzu/main.go +++ b/cmd/ponzu/main.go @@ -126,7 +126,7 @@ var ErrWrongOrMissingService = errors.New("To execute 'ponzu serve', " + var serveCmd = &cobra.Command{ Use: "serve [flags] ", Aliases: []string{"s"}, - Short: "actually run the server (serve is wrapped by the run command)", + Short: "run the server (serve is wrapped by the run command)", Hidden: true, RunE: func(cmd *cobra.Command, args []string) error { if len(args) == 0 { @@ -191,6 +191,9 @@ var serveCmd = &cobra.Command{ // 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 + if bind == "" { + bind = "localhost" + } err = db.PutConfig("bind_addr", bind) if err != nil { log.Fatalln("System failed to save config. Please try to run again.", err) -- cgit v1.2.3