summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2017-07-23 10:15:12 -0600
committerSteve Manuel <nilslice@gmail.com>2017-07-23 10:15:12 -0600
commit9ea0ec0e6fa0bd65c8d263a1cd418f83a3848a8b (patch)
tree92d30a45e38369bce7c9666c414657405fdacc8e
parent271bae22b9c954d76e96712a44fe4702f356d116 (diff)
adding bind option in CLI run cmd, including in system config
-rw-r--r--cmd/ponzu/main.go16
-rw-r--r--system/admin/config/config.go6
2 files changed, 19 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")
diff --git a/system/admin/config/config.go b/system/admin/config/config.go
index 19da39b..83ca2f7 100644
--- a/system/admin/config/config.go
+++ b/system/admin/config/config.go
@@ -14,6 +14,7 @@ type Config struct {
Name string `json:"name"`
Domain string `json:"domain"`
+ BindAddress string `json:"bind_addr"`
HTTPPort string `json:"http_port"`
HTTPSPort string `json:"https_port"`
AdminEmail string `json:"admin_email"`
@@ -54,6 +55,11 @@ func (c *Config) MarshalEditor() ([]byte, error) {
}),
},
editor.Field{
+ View: editor.Input("BindAddress", c, map[string]string{
+ "type": "hidden",
+ }),
+ },
+ editor.Field{
View: editor.Input("HTTPPort", c, map[string]string{
"type": "hidden",
}),