Add CORS support for user profile and account routes in the API
This commit is contained in:
@@ -241,15 +241,39 @@ func NewRouter(cfg *config.Config, db *database.DB, jwtManager *jwt.Manager, aut
|
||||
r.Put("/user/profile", func(w http.ResponseWriter, req *http.Request) {
|
||||
updateUserProfileHandler(w, req, db, auditLogger)
|
||||
})
|
||||
r.Options("/user/profile", func(w http.ResponseWriter, req *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "GET, PUT, OPTIONS")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
r.Post("/user/change-password", func(w http.ResponseWriter, req *http.Request) {
|
||||
changePasswordHandler(w, req, db, auditLogger)
|
||||
})
|
||||
r.Options("/user/change-password", func(w http.ResponseWriter, req *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
r.Post("/user/avatar", func(w http.ResponseWriter, req *http.Request) {
|
||||
uploadUserAvatarHandler(w, req, db, auditLogger, cfg)
|
||||
})
|
||||
r.Options("/user/avatar", func(w http.ResponseWriter, req *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
r.Delete("/user/account", func(w http.ResponseWriter, req *http.Request) {
|
||||
deleteUserAccountHandler(w, req, db, auditLogger, cfg)
|
||||
})
|
||||
r.Options("/user/account", func(w http.ResponseWriter, req *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "DELETE, OPTIONS")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
|
||||
// Org routes
|
||||
r.Get("/orgs", func(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user