papajuanito / grpc-node-server-reflection Goto Github PK
View Code? Open in Web Editor NEWgRPC Node Reflection Service Implementation.
gRPC Node Reflection Service Implementation.
Good day,
I have picked up a typo in the exported function name wrapServerWithRefelection
see
grpc-node-server-reflection/src/index.ts
Line 188 in bb150e3
It probably should be wrapServerWithReflection
I'm trying to use the well-known google types such as google.protobuf.Struct
and it appears that grpcurl
is failing with the following error.
$ grpcurl -plaintext localhost:50051 describe com.example.api.v1.ExampleAPI
Failed to resolve symbol "com.example.api.v1.ExampleAPI": file "com_example_api_v1.proto" included an unresolvable reference to "google.protobuf.Struct"
I'm guessing this happens because reflection API is not resolving the google.protobuf.*
types.
It does appear to work if you provide the -proto ./proto/example_api.proto
argument but this kind of defeats the point of implementing the reflection API because I don't want to ship the .proto
file with the client.
$ grpcurl -plaintext -proto src/proto/example_api.proto localhost:50051 describe com.example.api.v1.ExampleAPI
com.example.api.v1.ExampleAPI is a service:
service ExampleAPI {
rpc Exec ( .com.example.api.v1.Request ) returns ( .com.example.api.v1.Response );
}
.proto
file// ./proto/example_api.proto
syntax = "proto3";
package com.example.api.v1;
import "google/protobuf/struct.proto";
message Request {
google.protobuf.Struct body = 2;
}
message Response {
google.protobuf.Struct body = 2;
}
service ExampleAPI {
rpc Exec(Request) returns (Response);
}
// ./server.js
const path = require('path');
const grpc = require('grpc');
const protoLoader = require('@grpc/proto-loader');
const { default: wrapServerWithReflection } = require('grpc-node-server-reflection');
const server = wrapServerWithReflection(new grpc.Server());
const protoPath = path.join(__dirname, 'proto', 'example_api.proto');
const packageDefinition = protoLoader.loadSync(protoPath);
const serviceDescriptor = grpc.loadPackageDefinition(packageDefinition);
server.addService(
serviceDescriptor.com.example.api.v1.ExampleAPI.service, {
Exec: (call, callback) => {
console.log(call.request);
callback(null, {});
}
}
);
server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
server.start();
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.