Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/litichevskiydv/grpc-host-builder
Lightweight configurator for gRPC host
https://github.com/litichevskiydv/grpc-host-builder
Last synced: 3 months ago
JSON representation
Lightweight configurator for gRPC host
- Host: GitHub
- URL: https://github.com/litichevskiydv/grpc-host-builder
- Owner: litichevskiydv
- License: mit
- Archived: true
- Created: 2019-03-06T20:29:13.000Z (over 5 years ago)
- Default Branch: develop
- Last Pushed: 2022-09-05T04:00:48.000Z (about 2 years ago)
- Last Synced: 2024-04-18T16:59:25.471Z (7 months ago)
- Language: JavaScript
- Size: 454 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-grpc - grpc-host-builder - Lightweight library for building gRPC services with server side interceptors support (Language-Specific / Node.js)
README
# grpc-host-builder
[![npm version](https://badge.fury.io/js/grpc-host-builder.svg)](https://www.npmjs.com/package/grpc-host-builder)
[![npm downloads](https://img.shields.io/npm/dt/grpc-host-builder.svg)](https://www.npmjs.com/package/grpc-host-builder)
[![dependencies](https://img.shields.io/david/litichevskiydv/grpc-host-builder.svg)](https://www.npmjs.com/package/grpc-host-builder)
[![dev dependencies](https://img.shields.io/david/dev/litichevskiydv/grpc-host-builder.svg)](https://www.npmjs.com/package/grpc-host-builder)
[![Build Status](https://github.com/litichevskiydv/grpc-host-builder/actions/workflows/ci.yaml/badge.svg?branch=master)](https://github.com/litichevskiydv/grpc-host-builder/actions/workflows/ci.yaml)
[![Coverage Status](https://coveralls.io/repos/github/litichevskiydv/grpc-host-builder/badge.svg?branch=master)](https://coveralls.io/github/litichevskiydv/grpc-host-builder?branch=master)Lightweight configurator for gRPC host
## This was migrated to https://github.com/litichevskiydv/grpc-bay
This repository has been moved to the unified "monorepo". You can find the source under [/packages/grpc-host-builder](https://github.com/litichevskiydv/grpc-bay/tree/master/packages/grpc-host-builder).# Install
`npm i grpc-host-builder`
# Usage
```javascript
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();
```