Reputation: 1537
We implemented GRPC API using golang, and now need some mechanism to route requests on two different hosts (prod/stage). The problem is the routing rule must be depended on grpc metadata
, not the header. Actually we pass iOS version at metadata parameter. And as far as i know Nginx for example cannot do this. We have no k8s or something, just the simple API daemon listening on some port.
authConf := viper.GetStringMapString("auth")
creds, err := credentials.NewServerTLSFromFile(authConf["certfile"], authConf["keyfile"])
if err != nil {
panic(err)
}
lis, err := net.Listen("tcp", ":"+viper.GetString("port"))
if err != nil {
panic(err)
}
Upvotes: 0
Views: 632
Reputation: 18034
You can use envoy, which is a proxy just like NginX.
It has support for gRPC (take a look at grpc-web), which allows you to define multiple routes and redirect traffic to different hosts. I'm using it to redirect to different services based on the URL (which contains the gRPC package/function name), but it should also be possible to do the same with header or meta data.
Providing an actual envoy configuration that does this is out-of-scope on StackOverflow though.
Upvotes: 1