johanbrandhorst / grpc-gateway-boilerplate

All the boilerplate you need to get started with writing grpc-gateway powered REST services in Go
MIT License
474 stars 81 forks source link

Can I also use grpc-web? #23

Closed yehudamakarov closed 3 years ago

yehudamakarov commented 3 years ago

I'm trying to figure out how I would ALSO be able to open up a way for the mux to grab http 1.1 requests that are sendt via grpc-web.

It's not an issue, but I'm asking for some help, even for a good place to gather wisdom from.

See grpc-web:

grpcServer := grpc.Server()
wrappedGrpc := grpcweb.WrapServer(grpcServer)
tlsHttpServer.Handler = http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
    if wrappedGrpc.IsGrpcWebRequest(req) {
        wrappedGrpc.ServeHTTP(resp, req)
    }
    // Fall back to other servers.
    http.DefaultServeMux.ServeHTTP(resp, req)
})

I'm going to be trying it soon, but I'm still working on some architecture, and now I realize this has to be possible but I don't know how yet.

johanbrandhorst commented 3 years ago

Hi @yehudamakarov. It should certainly be possible to use grpc-web at the same time, though I would personally suggest settling on one solution. You can see my grpcweb-example repo for an example of using the Improbable in-process grpc-web proxy with a Go gRPC server.

If you want some reading material, I suggest reading my blog post from a few years ago, it's still pretty accurate: https://grpc.io/blog/state-of-grpc-web/. I don't think I'm going to add grpc-web support to this repo, so I'm going to close this issue. Feel free to reach out on Gophers Slack if you need more help.

yehudamakarov commented 3 years ago

Thank you @johanbrandhorst, I appreciate the reply, as well as your work and talks.

Reading through both of your example projects is putting it all together.

Also, I didn't even realize Google had their own grpc-web. So your article was great for context.

All the best!