Socket
Socket
Sign inDemoInstall

grpc-node-server-interceptors

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grpc-node-server-interceptors

This package provides an interface for gRPC Servers from `@grpc/grpc-js` to be created with interceptors. Allows for intercepting incoming requests from gRPC clients as well as intercepting outgoing responses from the server.


Version published
Weekly downloads
15
increased by66.67%
Maintainers
1
Weekly downloads
 
Created
Source

gRPC NodeJS Server Interceptors

This package provides an interface for gRPC Servers from @grpc/grpc-js to be created with interceptors. Allows for intercepting incoming requests from gRPC clients as well as intercepting outgoing responses from the server.

Installation

npm:

npm install grpc-node-server-interceptors

yarn:

yarn add grpc-node-server-interceptors

Examples

This example shows how to intercept incoming gRPC client requests on your gRPC server:

import { status as GrpcStatus } from '@grpc/grpc-js`;
import GrpcServerWithInterceptors, { ServerInterceptor, ServerInterceptingCall } from 'grpc-node-server-interceptors';

const interceptors: ServerInterceptor<RequestType, RequestResponse>[] = [
  (call, nextCall) => {
    return new ServerInterceptingCall(nextCall(call), {
      // This is called on every incoming client request before sent to the original handler
      onReceiveMessage: (message, next) => {
        // Continue unto the next interceptor
        next(message);
      },
      // This is called on every outgoing server response before it is sent to the client
      onSendMessage: (response, next) => {
        if (response.status !== GrpcStatus.OK) {
          log.error(response.status);
        }
        next(response);
      },
    });
  }
]

const server = new GrpcServerWithInterceptors({
  ...channelOptions,
  // List of global interceptors. These will be applied to all services added to the server through `addService`.
  interceptors,
});

// Consume the new server the same way you would with `grpc.Server`
server.addService(serviceDefinition, handlers);

server.bindAsync(...);

FAQs

Package last updated on 23 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc