Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grpc-ts-middleware

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grpc-ts-middleware

gRPC pre-call and post-call middleware

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

gRPC Middleware

A library that allows easy implementation of gRPC middleware, for both pre-call, and post-call.

Installation

npm install grpc-ts-middleware --save

Dependencies

  • gRPC: Node.js gRPC Library.

Usage

import * as grpc from 'grpc';
import GrpcMiddleware, { GrpcCall } from 'grpc-ts-middleware';

import { EchoReply, EchoRequest } from './proto/echo_pb';
import { EchoManagerService } from './proto/echo_grpc_pb';

const serviceName = 'echo.EchoManager';

function doEcho(call: grpc.ServerUnaryCall<EchoRequest>, callback: grpc.sendUnaryData<EchoReply>) {
	const reply = new EchoReply();
	reply.setMessage(call.request.getMessage());
	callback(null, reply);
}

function start(): grpc.Server {
	// Create the server
	const server: grpc.Server = new grpc.Server();

	// Create the middleware object
	const grpcMiddleware = new GrpcMiddleware(
		server,
		[
			(call: GrpcCall) => AppLogger.logger.debug('Pre-call handler 1', call),
			(call: GrpcCall) => AppLogger.logger.debug('Pre-call handler 2', call)
		],
		[
			(error: grpc.ServiceError | null, call: GrpcCall) =>
				AppLogger.logger.debug('Post-call handler 1', call, error),
			(error: grpc.ServiceError | null, call: GrpcCall) =>
				AppLogger.logger.debug('Post-call handler 2', call, error)
		]
	);
	// Add gRPC services that you want the middleware to monitor
	grpcMiddleware.addService(EchoManagerService, { echo: this.doEcho });
	// Enable propagation of Jaeger tracing headers
	grpcMiddleware.enableTracing();

	// Bind and start the server
	server.bind('localhost:9090', grpc.ServerCredentials.createInsecure());
	server.start();

	return server;
}

start();

Keywords

FAQs

Package last updated on 21 Dec 2018

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