diff --git a/cmd/cake_crm/main.go b/cmd/cake_crm/main.go index 070ced1..521ed30 100644 --- a/cmd/cake_crm/main.go +++ b/cmd/cake_crm/main.go @@ -64,9 +64,21 @@ func main() { gwServer := &http.Server{ Addr: ":8090", - Handler: mux, + Handler: cors(mux), } log.Println("Serving gRPC-Gateway on http://0.0.0.0:8090") log.Fatalln(gwServer.ListenAndServe()) } + +func cors(h 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-Methods", "GET, POST, PATCH, DELETE") + w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, Authorization, ResponseType") + if r.Method == "OPTIONS" { + return + } + h.ServeHTTP(w, r) + }) +}