Embedding clarification for subroutes.
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.
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.
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/