lab ab7b33e589
All checks were successful
continuous-integration/drone/push Build is passing
feat: add web middleware
2021-12-28 01:56:26 +08:00

17 lines
609 B
Go

package middleware
import "net/http"
func CORSHeaderMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Del("Content-Length")
w.Header().Set("Transfer-Encoding", "chunked")
w.Header().Set("Content-Type", "application/json;charset=utf-8")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
w.Header().Set("Access-Control-Allow-Methods", "GET,POST,PUT,PATCH,OPTIONS")
w.Header().Set("Access-Control-Allow-Credentials", "true")
next.ServeHTTP(w, r)
})
}