{"id":15287501,"url":"https://github.com/nicolaspearson/grpc.ts.middleware","last_synced_at":"2025-10-07T01:31:35.558Z","repository":{"id":33807989,"uuid":"162682440","full_name":"nicolaspearson/grpc.ts.middleware","owner":"nicolaspearson","description":"gRPC pre-call and post-call middleware","archived":true,"fork":false,"pushed_at":"2022-02-13T13:04:09.000Z","size":678,"stargazers_count":3,"open_issues_count":12,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-09T20:42:22.391Z","etag":null,"topics":["grpc","middleware","nodejs","tracing","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nicolaspearson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-21T07:39:01.000Z","updated_at":"2023-01-28T03:05:24.000Z","dependencies_parsed_at":"2022-08-07T23:15:19.399Z","dependency_job_id":null,"html_url":"https://github.com/nicolaspearson/grpc.ts.middleware","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolaspearson%2Fgrpc.ts.middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolaspearson%2Fgrpc.ts.middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolaspearson%2Fgrpc.ts.middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolaspearson%2Fgrpc.ts.middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nicolaspearson","download_url":"https://codeload.github.com/nicolaspearson/grpc.ts.middleware/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235575692,"owners_count":19012156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["grpc","middleware","nodejs","tracing","typescript"],"created_at":"2024-09-30T15:29:35.886Z","updated_at":"2025-10-07T01:31:30.286Z","avatar_url":"https://github.com/nicolaspearson.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gRPC Middleware\n\n[![License][license-image]][license-url]\n[![Current Version](https://img.shields.io/npm/v/grpc-ts-middleware.svg)](https://www.npmjs.com/package/grpc-ts-middleware)\n[![npm](https://img.shields.io/npm/dw/grpc-ts-middleware.svg)](https://www.npmjs.com/package/grpc-ts-middleware)\n![](https://img.shields.io/bundlephobia/min/grpc-ts-middleware.svg?style=flat)\n\n[license-url]: https://opensource.org/licenses/MIT\n[license-image]: https://img.shields.io/npm/l/make-coverage-badge.svg\n\nA library that assists with the implementation of gRPC pre-, and post-call middleware.\n\nThis library has **zero** external dependencies, but it is assumed that you are using the `grpc` library.\n\n### Installation\n\n```\nnpm install grpc-ts-middleware --save\n```\n\nInstall the `grpc` library:\n\n```\nnpm install grpc --save\n```\n\n### Dependencies\n\n- [gRPC](https://www.npmjs.com/package/grpc): Node.js gRPC Library.\n\n### Usage\n\n```typescript\nimport * as grpc from 'grpc';\nimport GrpcMiddleware, { GrpcCall } from 'grpc-ts-middleware';\n\nimport { EchoReply, EchoRequest } from './proto/echo_pb';\nimport { EchoManagerService } from './proto/echo_grpc_pb';\n\nfunction doEcho(call: grpc.ServerUnaryCall\u003cEchoRequest\u003e, callback: grpc.sendUnaryData\u003cEchoReply\u003e) {\n  const reply = new EchoReply();\n  reply.setMessage(call.request.getMessage());\n  callback(null, reply);\n}\n\nfunction start(): grpc.Server {\n  // Create the server\n  const server: grpc.Server = new grpc.Server();\n\n  // Create the middleware object\n  const grpcMiddleware = new GrpcMiddleware(\n    // An instance of the gRPC server\n    server,\n    // An array of functions to be invoked prior\n    // to the execution of the gRPC call\n    [\n      (call: GrpcCall) =\u003e console.log('Pre-call handler 1', call),\n      (call: GrpcCall) =\u003e console.log('Pre-call handler 2', call)\n    ],\n    // An array of functions to be invoked after the gRPC call\n    // has been executed, but before returning the result\n    [\n      (error: grpc.ServiceError | null, call: GrpcCall) =\u003e\n        console.log('Post-call handler 1', call, error),\n      (error: grpc.ServiceError | null, call: GrpcCall) =\u003e\n        console.log('Post-call handler 2', call, error)\n    ]\n  );\n  // Add gRPC services that you want the middleware to monitor\n  grpcMiddleware.addService(EchoManagerService, { echo: doEcho });\n  // Enable propagation of Jaeger tracing headers\n  grpcMiddleware.enableTracing();\n\n  // Bind and start the server\n  server.bind('localhost:9090', grpc.ServerCredentials.createInsecure());\n  server.start();\n\n  return server;\n}\n\nstart();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicolaspearson%2Fgrpc.ts.middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicolaspearson%2Fgrpc.ts.middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicolaspearson%2Fgrpc.ts.middleware/lists"}