grpc-host-builder
v6.4.4
Published
Lightweight configurator for gRPC host
Downloads
447
Maintainers
Readme
grpc-host-builder
Lightweight configurator for gRPC host
Install
npm i grpc-host-builder
Usage
const { GrpcHostBuilder } = require("grpc-host-builder");
/*...*/
class InterceptorForTom {
constructor(serverContext) {
this._logger = serverContext.createLogger();
}
async invoke(call, methodDefinition, next) {
/*...*/
if (call.request.name === "Tom") return { message: "Hello again, Tom!" };
return await next(call);
}
}
/*...*/
const server = await new GrpcHostBuilder()
.useLoggersFactory(loggersFactory)
.addInterceptor(InterceptorForTom)
.addInterceptor(async (call, methodDefinition, next) => {
if (call.request.name === "Jane") return { message: "Hello dear, Jane!" };
return await next(call);
})
.addService(packageObject.v1.Greeter.service, {
sayHello: (call) => {
const request = new HelloRequest(call.request);
return new HelloResponse({ message: `Hello, ${request.name}!` });
},
})
.bind(grpcBind)
.buildAsync();