grpc-gatewayでのCORS対策


https://github.com/grpc-ecosystem/grpc-gateway/issues/132
にある通りに、gorilla.handlers.CORS が使えるので、ありがたく使わせていただく。

下記のように使う。

mux := runtime.NewServeMux(opts...)
newMux := handlers.CORS(
    handlers.AllowedMethods([]string{"GET", "POST", "OPTIONS"}),
    handlers.AllowedOrigins([]string{"http://localhost:3000"}),
    handlers.AllowedHeaders([]string{"content-type", "x-foobar-key"}),
)(mux)
http.ListenAndServe(":8080", newMux)