add cors
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
ffd1396739
commit
1ea3b427bd
|
@ -64,9 +64,21 @@ func main() {
|
||||||
|
|
||||||
gwServer := &http.Server{
|
gwServer := &http.Server{
|
||||||
Addr: ":8090",
|
Addr: ":8090",
|
||||||
Handler: mux,
|
Handler: cors(mux),
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("Serving gRPC-Gateway on http://0.0.0.0:8090")
|
log.Println("Serving gRPC-Gateway on http://0.0.0.0:8090")
|
||||||
log.Fatalln(gwServer.ListenAndServe())
|
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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue