17 lines
609 B
Go
Raw Normal View History

2021-12-28 01:56:26 +08:00
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)
})
}