17 lines
609 B
Go
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)
|
|
})
|
|
}
|