add cors
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Владимир Фёдоров 2024-05-22 04:07:25 +07:00
parent ffd1396739
commit 1ea3b427bd
1 changed files with 13 additions and 1 deletions

View File

@ -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)
})
}