summaryrefslogtreecommitdiff
path: root/cmd/ponzu
diff options
context:
space:
mode:
authorSteve <nilslice@gmail.com>2017-01-16 16:14:00 -0800
committerGitHub <noreply@github.com>2017-01-16 16:14:00 -0800
commit2af951230eddc45ba429cff10d7566ad98fd343b (patch)
tree7543be03fae8aeeacc8eb48dbe16ab2d42fbca0b /cmd/ponzu
parent3249b82b2a4f1aa0ae9e6943cd72dd7eebae8a4a (diff)
[core] Adding toggle for CORS, GZIP in admin/cms configuration (#30)
This PR enables admins to disable/enable CORS and GZIP from within the admin CMS configuration page. Both are enabled by default. Note: currently, the GZIP implementation is 100% on the fly, for every qualifying API endpoint request. This could add significant CPU usage, but dramatically decreases bandwidth. Will be considering other better implementations, but for now YMMV. Possible optimizations: - pooling gzip Writers vs. creating a new one for each response - caching gzipped responses (in memory? on disk?) - enforcing size threshold (only gzip content larger than N bytes)
Diffstat (limited to 'cmd/ponzu')
-rw-r--r--cmd/ponzu/main.go31
-rw-r--r--cmd/ponzu/usage.go20
2 files changed, 28 insertions, 23 deletions
diff --git a/cmd/ponzu/main.go b/cmd/ponzu/main.go
index 90ad613..e90d318 100644
--- a/cmd/ponzu/main.go
+++ b/cmd/ponzu/main.go
@@ -80,7 +80,7 @@ func main() {
case "new":
if len(args) < 2 {
- fmt.Println(usage)
+ fmt.Println(usageNew)
os.Exit(0)
}
@@ -91,15 +91,22 @@ func main() {
}
case "generate", "gen", "g":
- if len(args) < 2 {
- flag.PrintDefaults()
+ if len(args) < 3 {
+ fmt.Println(usageGenerate)
os.Exit(0)
}
- err := generateContentType(args[1:])
- if err != nil {
- fmt.Println(err)
- os.Exit(1)
+ // check what we are asked to generate
+ switch args[1] {
+ case "content", "c":
+ err := generateContentType(args[2:])
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+ default:
+ msg := fmt.Sprintf("Generator '%s' is not implemented.", args[1])
+ fmt.Println(msg)
}
case "build":
@@ -163,8 +170,10 @@ func main() {
for i := range services {
if services[i] == "api" {
api.Run()
+
} else if services[i] == "admin" {
admin.Run()
+
} else {
fmt.Println("To execute 'ponzu serve', you must specify which service to run.")
fmt.Println("$ ponzu --help")
@@ -176,7 +185,7 @@ 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.")
+ log.Fatalln("System failed to save config. Please try to run again.", err)
}
// cannot run production HTTPS and development HTTPS together
@@ -193,16 +202,18 @@ func main() {
fmt.Println("Enabling HTTPS...")
go tls.Enable()
- fmt.Printf("Server listening on :%s for HTTPS requests...\n", db.ConfigCache("https_port"))
+ fmt.Printf("Server listening on :%s for HTTPS requests...\n", db.ConfigCache("https_port").(string))
}
// 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))
if err != nil {
- log.Fatalln("System failed to save config. Please try to run again.")
+ 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))
case "":
diff --git a/cmd/ponzu/usage.go b/cmd/ponzu/usage.go
index 2dca46d..2d7a3b8 100644
--- a/cmd/ponzu/usage.go
+++ b/cmd/ponzu/usage.go
@@ -10,11 +10,10 @@ var year = fmt.Sprintf("%d", time.Now().Year())
var usageHeader = `
$ ponzu [flags] command <params>
-Ponzu is a powerful and efficient open-source "Content-as-a-Service" system
-framework and CMS. It provides automatic, free, and secure HTTP/2 over TLS
-(certificates obtained via Let's Encrypt - https://letsencrypt.org), a useful
-CMS and scaffolding to generate content editors, and a fast HTTP API on which
-to build modern applications.
+Ponzu is a powerful and efficient open-source HTTP server framework and CMS. It
+provides automatic, free, and secure HTTP/2 over TLS (certificates obtained via
+[Let's Encrypt](https://letsencrypt.org)), a useful CMS and scaffolding to
+generate content editors, and a fast HTTP API on which to build modern applications.
Ponzu is released under the BSD-3-Clause license (see LICENSE).
(c) ` + year + ` Boss Sauce Creative, LLC
@@ -55,17 +54,12 @@ new <directory>:
`
var usageGenerate = `
-generate, gen, g <type (,...fields)>:
+generate, gen, g <generator type (,...fields)>:
- Generate a content type file with boilerplate code to implement
- the editor.Editable interface. Must be given one (1) parameter of
- the name of the type for the new content. The fields following a
- type determine the field names and types of the content struct to
- be generated. These must be in the following format:
- fieldName:"T"
+ Generate boilerplate code for various Ponzu components, such as 'content'.
Example:
- $ ponzu gen review title:"string" body:"string" rating:"int" tags:"[]string"
+ $ ponzu gen content review title:"string" body:"string" rating:"int" tags:"[]string"
The command above will generate a file 'content/review.go' with boilerplate
methods, as well as struct definition, and cooresponding field tags like: