首页 > 解决方案 > 如何从 NodeJS 服务器调用 grpc-web 代理

问题描述

我正在运行实现服务接口的 gRPC 服务器和允许客户端连接的 Envoy 代理,health.js使用 webpack 构建并引用dist/main.js到 HTML 文件中的以下 js 代码(文件)进行成功调用,它的工作

const { HealthCheckRequest, HealthCheckReply } = require("./protobuf/service_pb")
const { ProtoClient } = require("./protobuf/service_grpc_web_pb")
var client = new ProtoClient('http://localhost:8080');

var request = new HealthCheckRequest()
client.healthCheck(request, {}, (err, response) => {
    console.log(response)
})

我想在NodeJS服务器而不是浏览器中执行此功能,实际上执行命令node health.js时发生以下错误

...
ReferenceError: XMLHttpRequest is not defined
...

标签: envoyproxygrpc-web

解决方案


目前没有对此的支持。您可以在https://github.com/grpc/grpc-node上通过我们的存储库创建功能请求

由于它实际上是不同的协议,因此需要编写新代码来支持它。


推荐阅读