diff options
author | Steve Manuel <nilslice@gmail.com> | 2017-01-13 15:48:38 -0800 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2017-01-13 15:48:38 -0800 |
commit | 317dcbdda41cafbd5a330602b38b9a52fab5ec6f (patch) | |
tree | 23be361cc3d69a33d2aa88bf49c6586ff44b7afa | |
parent | af31558e3d90b887758d9266c5ba80f0d9eaf3dc (diff) |
adding test in CORS middleware in fix for start
-rw-r--r-- | system/admin/config/config.go | 2 | ||||
-rw-r--r-- | system/admin/handlers.go | 2 | ||||
-rw-r--r-- | system/admin/server.go | 3 | ||||
-rw-r--r-- | system/api/handlers.go | 9 | ||||
-rw-r--r-- | system/api/server.go | 7 |
5 files changed, 15 insertions, 8 deletions
diff --git a/system/admin/config/config.go b/system/admin/config/config.go index a028ebf..ba12515 100644 --- a/system/admin/config/config.go +++ b/system/admin/config/config.go @@ -79,7 +79,7 @@ func (c *Config) MarshalEditor() ([]byte, error) { View: editor.Checkbox("DisableCORS", c, map[string]string{ "label": "Disable CORS (so only " + c.Domain + " can fetch your data)", }, map[string]string{ - "on": "Disable", + "true": "Disable", }), }, editor.Field{ diff --git a/system/admin/handlers.go b/system/admin/handlers.go index 00add87..2bea356 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -1533,7 +1533,7 @@ func editHandler(res http.ResponseWriter, req *http.Request) { // create a timestamp if one was not set if ts == "" { - ts := fmt.Sprintf("%d", int64(time.Nanosecond)*time.Now().UnixNano()/int64(time.Millisecond)) + ts = fmt.Sprintf("%d", int64(time.Nanosecond)*time.Now().UnixNano()/int64(time.Millisecond)) req.PostForm.Set("timestamp", ts) } diff --git a/system/admin/server.go b/system/admin/server.go index 991f2d2..8b759e4 100644 --- a/system/admin/server.go +++ b/system/admin/server.go @@ -1,6 +1,7 @@ package admin import ( + "fmt" "log" "net/http" "os" @@ -54,4 +55,6 @@ func Run() { http.Handle("/api/uploads/", api.Record(api.CORS(db.CacheControl( http.StripPrefix("/api/uploads/", http.FileServer( restrict(http.Dir(uploadsDir)))))))) + + fmt.Println("Admin routes registered.") } diff --git a/system/api/handlers.go b/system/api/handlers.go index 0be98a4..de7fbcb 100644 --- a/system/api/handlers.go +++ b/system/api/handlers.go @@ -254,13 +254,12 @@ func sendPreflight(res http.ResponseWriter) { // CORS wraps a HandleFunc to respond to OPTIONS requests properly func CORS(next http.HandlerFunc) http.HandlerFunc { - if db.ConfigCache("cors_disabled").([]string)[0] == "true" { - return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + return db.CacheControl(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + if db.ConfigCache("cors_disabled").(bool) == true { res.WriteHeader(http.StatusForbidden) - }) - } + return + } - return db.CacheControl(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { if req.Method == http.MethodOptions { sendPreflight(res) return diff --git a/system/api/server.go b/system/api/server.go index 4b8b22e..e2af125 100644 --- a/system/api/server.go +++ b/system/api/server.go @@ -1,6 +1,9 @@ package api -import "net/http" +import ( + "fmt" + "net/http" +) // Run adds Handlers to default http listener for API func Run() { @@ -11,4 +14,6 @@ func Run() { http.HandleFunc("/api/content", Record(CORS(contentHandler))) http.HandleFunc("/api/content/external", Record(CORS(externalContentHandler))) + + fmt.Println("API routes registered.") } |