Ninja Pumpkin Mutants

    grpc-host-builder
    TypeScript icon, indicating that this package has built-in type declarations

    5.4.3 • Public • Published

    grpc-host-builder

    npm version npm downloads

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

    Install

    npm i grpc-host-builder

    DownloadsWeekly Downloads

    4

    Version

    5.4.3

    License

    MIT

    Unpacked Size

    23 kB

    Total Files

    15

    Last publish

    Collaborators

    • dmitriy.litichevskiy