From e1c879a478ba533393079d077ac421bc5fbfb106 Mon Sep 17 00:00:00 2001 From: Qian Wang Date: Tue, 30 Jul 2019 23:49:22 +0100 Subject: [PATCH] Fix CORS and POST handler --- internal/server/um_local.go | 3 +++ internal/server/um_local_hlr.go | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/server/um_local.go b/internal/server/um_local.go index ff50c13..2c9cbec 100644 --- a/internal/server/um_local.go +++ b/internal/server/um_local.go @@ -56,6 +56,9 @@ func (manager *localManager) registerMux() *gmux.Router { r.HandleFunc("/admin/users/{UID}", manager.getUserInfoHlr).Methods("GET") r.HandleFunc("/admin/users/{UID}", manager.writeUserInfoHlr).Methods("POST") r.HandleFunc("/admin/users/{UID}", manager.deleteUserHlr).Methods("DELETE") + r.Methods("OPTIONS").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Access-Control-Allow-Methods", "GET,POST,DELETE,OPTIONS") + }) r.Use(corsMiddleware) return r } diff --git a/internal/server/um_local_hlr.go b/internal/server/um_local_hlr.go index 2393ff2..e442f1a 100644 --- a/internal/server/um_local_hlr.go +++ b/internal/server/um_local_hlr.go @@ -96,7 +96,7 @@ func (manager *localManager) writeUserInfoHlr(w http.ResponseWriter, r *http.Req return } - jsonUinfo := gmux.Vars(r)["UserInfo"] + jsonUinfo := r.FormValue("UserInfo") if jsonUinfo == "" { http.Error(w, "UserInfo cannot be empty", http.StatusBadRequest) return @@ -112,7 +112,7 @@ func (manager *localManager) writeUserInfoHlr(w http.ResponseWriter, r *http.Req } err = manager.db.Update(func(tx *bolt.Tx) error { - bucket, err := tx.CreateBucket(uinfo.UID) + bucket, err := tx.CreateBucketIfNotExists(uinfo.UID) if err != nil { return err }