question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I am unable to use grpc-web wrapped server with normal grpc client?

See original GitHub issue

https://github.com/gustavohenrique/grpc-web-golang-vuejs/tree/master/backend I have this backend server which is successfully communicating with the vue.js client. But i am unable to call the grpc function with the normal grpc client. Is it possible to use grpcweb wrapped server with both browser based app as well as normal backend clients? If yes then how?

Here is the small code which i was trying to connect to it…

package main
import (
	"context"
	"fmt"
	"io"
	"log"
	"time"

	pb "backend/proto"

	"google.golang.org/grpc"
)
func main() {

	fmt.Println("Hello I'm a client")
	conn, err := grpc.Dial("0.0.0.0:9000", grpc.WithInsecure())
	if err != nil {
		log.Fatalf("could not connect: %v", err)
	}
	defer conn.Close()
	c := pb.NewAccountServiceClient(conn)
	doUnary(c)
}
func doUnary(c pb.AccountServiceClient) {
	fmt.Println("do unary from the client")
	req := &pb.User{
		Email:    "hh1212",
		Password: "23123",
	}
	res, err := c.Create(context.Background(), req)
	if err != nil {
		log.Fatalf("error while calling Greet RPC: %v", err)
	}
	
	//log.Printf("Response from Greet: %v", res.GetEmail())
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
johanbrandhorstcommented, Apr 27, 2021

šŸ¤·šŸ» you can check out my example repositories and see if they work for you. I’m guessing there’s something going on with your local set up, not much I can help with there.

1reaction
johanbrandhorstcommented, Apr 27, 2021

No, that’s not enough. I explained that you need to split the traffic. Your handler is just replying with nothing when the request isn’t a grpc-web request. You need to add `grpcServer.ServeHTTP inside your handler:

    http.HandleFunc("/", func(resp http.ResponseWriter, req *http.Request) {
        if grpc.IsGrpcWebRequest(req) || grpc.IsAcceptableGrpcCorsRequest(req) {
            allowCors(resp, req)
            grpc.ServeHTTP(resp, req)
            return
        }
        grpcServer.ServeHTTP(resp, req)
    })
Read more comments on GitHub >

github_iconTop Results From Across the Web

Does grpcweb.WrapServer respect client deadlines? #1029
Hi, I'm using code like this go func() { defer func() { if r := recover(); r != nil { log. ... On...
Read more >
grpcweb wrapped server functions call via golang client?
This project is using grpcweb wrapped server. Then i wrote a small client to call the grpc server functions But it is not...
Read more >
gRPC: Go Server & Web Client
Because if the gRPC Web client wants to communicate with gRPC server, we need to modify the server to wrap the gRPC server...
Read more >
An all-in-one guide to gRPC-Gateway
gRPC -Gateway is a plugin that can be used to generate a reverse proxy server for gRPC services that convert Restful/JSON into gRPC....
Read more >
The state of gRPC in the browser
The basic idea is to have the browser send normal HTTP requests (with ... The Google gRPC-Web client is implemented in JavaScript using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found