Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedding clarification for subroutes. #209

Open
delaneyj opened this issue Dec 30, 2022 · 2 comments
Open

Embedding clarification for subroutes. #209

delaneyj opened this issue Dec 30, 2022 · 2 comments

Comments

@delaneyj
Copy link

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.

@jhump
Copy link
Contributor

jhump commented Jan 4, 2023

Apologies if it's unclear, but this is mentioned briefly in the doc comments: https://pkg.go.dev/github.com/fullstorydev/grpcui@v1.3.1/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.

@eqinox76
Copy link

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants