alexkappa / service-template-grpc

0 stars 2 forks source link

Suggestions for additional support frameworks #1

Open yinzara opened 4 years ago

yinzara commented 4 years ago

I highly suggest adding "grpc-web" support to your microservice. That will allow any web browser to connect directly to the service using gRPC without having to use RESTful JSON.

See: "github.com/improbable-eng/grpc-web/go/grpcweb"

handler = grpcweb.WrapHandler(handler,
    grpcweb.WithCorsForRegisteredEndpointsOnly(false),
    grpcweb.WithOriginFunc(func(origin string) bool {
      return true
    }),
    grpcweb.WithAllowNonRootResource(false),
  )

I also suggest adding cors support as well as an option.

See: "github.com/rs/cors"

handler = cors.New(cors.Options{
      AllowedMethods: []string{
        http.MethodHead,
        http.MethodGet,
        http.MethodPost,
        http.MethodPut,
        http.MethodPatch,
        http.MethodDelete,
      },
      AllowOriginFunc: func(origin string) bool {
        return true
      },
      AllowedHeaders:   []string{"*"},
      AllowCredentials: true,
    }).Handler(handler)

And if you need unencrypted HTTP 2.0 support.

See: "golang.org/x/net/http2" "golang.org/x/net/http2/h2c"

    handler = h2c.NewHandler(handler, &http2.Server{})
alexkappa commented 4 years ago

Nice suggestions! I'll do some reading :) Thanks