grpcui icon indicating copy to clipboard operation
grpcui copied to clipboard

Embedding clarification for subroutes.

Open delaneyj opened this issue 3 years ago • 2 comments

Can embed grpcui in a server and its working great via

target := "localhost:4321"
cc, err := grpc.DialContext(ctx, target, grpc.WithBlock(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
 return err
}
h, err := standalone.HandlerViaReflection(ctx, cc, target)
if err != nil {
  return err
}
router.Mount("/", h)

However I have want to mount to router.Mount("/ui", h). That doesn't work and I'm wondering if its even possible or is there parts that expect to be absolute to the root path. Any guidance would be wonderful.

delaneyj avatar Dec 30 '22 16:12 delaneyj

Apologies if it's unclear, but this is mentioned briefly in the doc comments: https://pkg.go.dev/github.com/fullstorydev/[email protected]/standalone#Handler

The returned handler expects to serve resources from "/". If it will instead be handling a sub-path (e.g. handling "/rpc-ui/") then use http.StripPrefix.

jhump avatar Jan 04 '23 00:01 jhump

I am also trying to host grpcui on a subroute and got some unhelpful http 301 redirects to '/'. But using http.StripPrefix correctly works fine:

mux.Handle("/ui/", http.StripPrefix("/grpc-ui", h))

Now point your Browser to http://localhost:9192//grpc-ui/

eqinox76 avatar Jul 20 '23 08:07 eqinox76