LoginSignup
9
2

More than 5 years have passed since last update.

grpc-gatewayでのCORS対策

Last updated at Posted at 2018-06-18

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)
9
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
2