4

I am working with grpc-web, essentially trying to port a working server side vanilla grpc/node example to the browser. My existing node client example connects to the grpc service like so.

var services = require('./my_services_grpc_pb'); 
var grpc = require('grpc');  

var secureClient = new services.MyServicesServiceClient(                                                                                                                                                           
    (host + ":" + port),                                                                                                                                                                                           
    grpc.credentials.createSsl(                                                                                                                                                                                    
        fs.readFileSync(certFile)                                                                                                                                                                                  
    )                                                                                                                                                                                                              
);                                                                                                                                                                                                                 

That seems to do what I want. However, when I try to include the line

var grpc = require('grpc');

And then bundle my code with webpack, I get an error "cannot resolve child_process". I did a bit of googling and found that child_process does not work in the browser. I'm in a bit of a bind now, because the code examples that I saw on the web-grpc-tutorial do not seem show how to establish a secure connection. They look like this

var echoService = new EchoServiceClient('http://localhost:8080');

How would I go about passing certs to the call/establishing a secure channel?

Zack
  • 13,454
  • 24
  • 75
  • 113

1 Answers1

0

There is an example of using grpc-web with TLS here: https://github.com/salrashid123/grpc_web_with_gke. There's a section on how to use certs. You do not have to use GKE if you don't need to.

Stanley Cheung
  • 347
  • 1
  • 3