update restful api

This commit is contained in:
steven
2021-12-09 22:02:57 +08:00
parent bdaeb3a68b
commit a08ad0ebab
17 changed files with 520 additions and 94 deletions

View File

@ -1,7 +1,7 @@
package api
import (
"memos/common/error"
"memos/api/e"
"net/http"
)
@ -10,10 +10,19 @@ func AuthCheckerMiddleWare(next http.Handler) http.Handler {
userId, err := GetUserIdInCookie(r)
if err != nil || userId == "" {
error.ErrorHandler(w, "NOT_AUTH")
e.ErrorHandler(w, "NOT_AUTH", "Need authorize")
return
}
next.ServeHTTP(w, r)
})
}
func CorsMiddleWare(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
next.ServeHTTP(w, r)
})
}