diff options
author | Steve <nilslice@gmail.com> | 2017-01-16 16:14:00 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-16 16:14:00 -0800 |
commit | 2af951230eddc45ba429cff10d7566ad98fd343b (patch) | |
tree | 7543be03fae8aeeacc8eb48dbe16ab2d42fbca0b /system/db/init.go | |
parent | 3249b82b2a4f1aa0ae9e6943cd72dd7eebae8a4a (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 'system/db/init.go')
-rw-r--r-- | system/db/init.go | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/system/db/init.go b/system/db/init.go index eaf6d76..9125d3b 100644 --- a/system/db/init.go +++ b/system/db/init.go @@ -1,10 +1,8 @@ package db import ( - "encoding/json" "log" - "github.com/ponzu-cms/ponzu/system/admin/config" "github.com/ponzu-cms/ponzu/system/item" "github.com/boltdb/bolt" @@ -57,32 +55,23 @@ func Init() { } } - // seed db with configs structure if not present - b := tx.Bucket([]byte("__config")) - if b.Get([]byte("settings")) == nil { - j, err := json.Marshal(&config.Config{}) - if err != nil { - return err - } - - err = b.Put([]byte("settings"), j) - if err != nil { - return err - } - } - - clientSecret := ConfigCache("client_secret") - - if clientSecret != "" { - jwt.Secret([]byte(clientSecret)) - } - return nil }) if err != nil { log.Fatalln("Coudn't initialize db with buckets.", err) } + err = LoadCacheConfig() + if err != nil { + log.Fatalln("Failed to load config cache.", err) + } + + clientSecret := ConfigCache("client_secret").(string) + + if clientSecret != "" { + jwt.Secret([]byte(clientSecret)) + } + // invalidate cache on system start err = InvalidateCache() if err != nil { @@ -103,6 +92,9 @@ func SystemInitComplete() bool { err := store.View(func(tx *bolt.Tx) error { users := tx.Bucket([]byte("__users")) + if users == nil { + return bolt.ErrBucketNotFound + } err := users.ForEach(func(k, v []byte) error { complete = true |