Skip to content
This repository has been archived by the owner on Sep 5, 2022. It is now read-only.

Latest commit

 

History

History
56 lines (43 loc) · 2.15 KB

README.md

File metadata and controls

56 lines (43 loc) · 2.15 KB

grpc-host-builder

npm version npm downloads dependencies dev dependencies Build Status Coverage Status

Lightweight configurator for gRPC host

This repository has been moved to the unified "monorepo". You can find the source under /packages/grpc-host-builder.

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();