const root_cert = fs.readFileSync('path/to/root-cert');
const ssl_creds = grpc.credentials.createSsl(root_cert);
const stub = new helloworld.Greeter('myservice.example.com', ssl_creds);
但这个案例没说域名怎么配置。
我的:
const a= fs.readFileSync(path.join(__dirname,"/ca.crt"))//证书路径
const ssl_creds = grpc.credentials.createSsl(a);
const client = new helloworld.Greeter('xx.xx.xx.xx:xxxx', ssl_creds,{'grpc.ssl_target_name_override':'域名'});
client.sayHello(Request, (error, response) => {
if (error) {
console.log(error);
return;
}
console.log(response);
})