1.3.1 • Published 5 years ago
ges v1.3.1
grpc-experimental-server
gRPC experimental server that supports koa-like interceptors
Usage
npm i ges grpcimport ExperimentalServer from 'ges';
const server = new ExperimentalServer();
server.addService(/* ... */);
// add interceptor
server.use(async (context, next) => {
// preprocess
const start = Date.now();
try {
await next();
} finally {
// postprocess
const costtime = Date.now() - start;
console.log('costtime is', costtime);
console.log('unary response is ', context.response);
}
});
serer.bind(/* ... */);
server.start();gRPC has 4 kinds of call:
| handle type | request is stream or not | response is stream or not |
|---|---|---|
| handleUnaryCall | ❌ | ❌ |
| handleClientStreamingCall | ✅ | ❌ |
| handleServerStreamingCall | ❌ | ✅ |
| handleBidiStreamingCall | ✅ | ✅ |
Context
callcurrent gRPC calldefinitionthe method definition of current callresponseresponse if response is notstreamonFinished(...)you can listen on call finish event, no matter response of current call is stream or not. So you don't need to care about what kind is the call. It is very useful to do something liketracing,logging
Notes
await next()would wait the call to be finished if response is not stream.
1.3.1
5 years ago
2.0.0-alpha.1
6 years ago
2.0.0-alpha.2
6 years ago
2.0.0-alpha.0
6 years ago
1.3.0
6 years ago
1.2.2
6 years ago
1.1.1
6 years ago
1.1.0
6 years ago
1.0.2
6 years ago