diff options
author | Steve Manuel <nilslice@gmail.com> | 2017-01-04 10:27:10 -0800 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2017-01-04 10:27:10 -0800 |
commit | fc51643434c5eef8417a62b9f83fec3823c393ec (patch) | |
tree | cc14f61b15c0b7e88608f30c4a82b35ccb92b660 | |
parent | 76ae3f53e0c294f13c15fccd9be89ec472a8deee (diff) |
adding httpsport and https_port to flags and config
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | cmd/ponzu/main.go | 28 | ||||
-rw-r--r-- | system/admin/config/config.go | 6 | ||||
-rw-r--r-- | system/tls/enable.go | 3 |
4 files changed, 29 insertions, 15 deletions
@@ -28,12 +28,12 @@ rapid development, but need a fast JSON response in a high-concurrency environme - Development: self-signed certificates auto-generated - Production: auto-renewing certificates fetched from [Let's Encrypt](https://letsencrypt.org) -Because you want to turn this: +**Because you want to turn this:** ```bash $ ponzu generate song title:"string" artist:"string" rating:"int" opinion:"string" spotify_url:"string" ``` -Into this: +**Into this:**  @@ -147,7 +147,8 @@ if the server should utilize TLS encryption - served over HTTPS, which is automatically managed using Let's Encrypt (https://letsencrypt.org) Optional flags: -- `--port` sets the port on which the server listens for requests [defaults to 8080] +- `--port` sets the port on which the server listens for HTTP requests [defaults to 8080] +- `--httpsport` sets the port on which the server listens for HTTPS requests [defaults to 443] - `--https` enables auto HTTPS management via Let's Encrypt (port is always 443) - `--devhttps` generates self-signed SSL certificates for development-only (port is 10443) diff --git a/cmd/ponzu/main.go b/cmd/ponzu/main.go index 440ce70..b68065c 100644 --- a/cmd/ponzu/main.go +++ b/cmd/ponzu/main.go @@ -20,10 +20,11 @@ import ( ) var ( - usage = usageHeader + usageNew + usageGenerate + usageBuild + usageRun - port int - https bool - devhttps bool + usage = usageHeader + usageNew + usageGenerate + usageBuild + usageRun + port int + httpsport int + https bool + devhttps bool // for ponzu internal / core development dev bool @@ -36,7 +37,8 @@ func main() { fmt.Println(usage) } - flag.IntVar(&port, "port", 8080, "port for ponzu to bind its listener") + flag.IntVar(&port, "port", 8080, "port for ponzu to bind its HTTP listener") + flag.IntVar(&httpsport, "httpsport", 443, "port for ponzu to bind its HTTPS listener") flag.BoolVar(&https, "https", false, "enable automatic TLS/SSL certificate management") flag.BoolVar(&devhttps, "devhttps", false, "[dev environment] enable automatic TLS/SSL certificate management") flag.BoolVar(&dev, "dev", false, "modify environment for Ponzu core development") @@ -128,7 +130,7 @@ func main() { } serve := exec.Command("./ponzu-server", - fmt.Sprintf("--port=%d", port), + fmt.Sprintf("--port=%d --httpsport=%d", port, httpsport), addTLS, "serve", services, @@ -171,12 +173,18 @@ func main() { } } + // save the https port the system is listening on + err := db.PutConfig("https_port", fmt.Sprintf("%d", httpsport)) + if err != nil { + log.Fatalln("System failed to save config. Please try to run again.") + } + // cannot run production HTTPS and development HTTPS together if devhttps { fmt.Println("Enabling self-signed HTTPS... [DEV]") go tls.EnableDev() - fmt.Println("Server listening on https://localhost:10443 for requests... [DEV]") + fmt.Printf("Server listening on https://localhost:%s for requests... [DEV]\n", db.ConfigCache("https_port")) fmt.Println("----") fmt.Println("If your browser rejects HTTPS requests, try allowing insecure connections on localhost.") fmt.Println("on Chrome, visit chrome://flags/#allow-insecure-localhost") @@ -185,12 +193,12 @@ func main() { fmt.Println("Enabling HTTPS...") go tls.Enable() - fmt.Println("Server listening on :443 for HTTPS requests...") + fmt.Printf("Server listening on :%s for HTTPS requests...\n", db.ConfigCache("https_port")) } - // save the port the system is listening on so internal system can make + // save the https port 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("http_port", fmt.Sprintf("%d", port)) + err = db.PutConfig("http_port", fmt.Sprintf("%d", port)) if err != nil { log.Fatalln("System failed to save config. Please try to run again.") } diff --git a/system/admin/config/config.go b/system/admin/config/config.go index fdc1ae4..2bc80c6 100644 --- a/system/admin/config/config.go +++ b/system/admin/config/config.go @@ -13,6 +13,7 @@ type Config struct { Name string `json:"name"` Domain string `json:"domain"` HTTPPort string `json:"http_port"` + HTTPSPort string `json:"https_port"` AdminEmail string `json:"admin_email"` ClientSecret string `json:"client_secret"` Etag string `json:"etag"` @@ -46,6 +47,11 @@ func (c *Config) MarshalEditor() ([]byte, error) { }), }, editor.Field{ + View: editor.Input("HTTPSPort", c, map[string]string{ + "type": "hidden", + }), + }, + editor.Field{ View: editor.Input("AdminEmail", c, map[string]string{ "label": "Adminstrator Email (will be notified of internal system information)", }), diff --git a/system/tls/enable.go b/system/tls/enable.go index c6f65b3..f9c16d8 100644 --- a/system/tls/enable.go +++ b/system/tls/enable.go @@ -10,7 +10,6 @@ import ( "time" "github.com/ponzu-cms/ponzu/system/db" - "golang.org/x/crypto/acme/autocert" ) @@ -71,7 +70,7 @@ func Enable() { setup() server := &http.Server{ - Addr: ":443", + Addr: fmt.Sprintf(":%s", db.ConfigCache("https_port")), TLSConfig: &tls.Config{GetCertificate: m.GetCertificate}, } |