1.1.0 • Published 9 months ago

node-grpc-web-wrapper v1.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

grpc-web node in-process translator

grpc-web currently uses http1 in the browser client due to the inability of xhr or fetch to support the same features as http2

grpc-web docs recommend using envoy proxy as a solution to support web clients with existing backend serivces, which creates an additional architectural requirement

this package provides standalone grpc-web service for node, similar to grpc go wrapper and the tonic web wrapper. it also exposes a generic wrapper endpoint that can be incrementally added to any existing node service with a generic http.IncomingMessage (e.g. express, next.js, hapi etc) to provide further flexibility

features currently supported

  • unary services
  • server streaming services
  • metadata/trailers
  • deadlines

features not currently supported

  • client streaming (not officially supported by gRPC-web)
  • bidi streaming (not officially supported by gRPC-web)
  • binary wire format (not officially supported by gRPC-web for server streaming)

usage

with existing node servers

see /examples for full working example of a simple chat app using React Hooks and Express

const chatServer: grpc.Server = createGrpcServer();

app.post("*", (req, res) => {
  // pass req res to callback with the grpc server
  grpcWebHandler(chatServer, req, res);
});

standalone

import GrpcWebServer from "node-grpc-web-wrapper";
import * as grpc from "@grpc/grpc-js";

const server = new grpc.Server();

const myGrpcService: MyGrpcService = {
    ...handler definiitions
};

GrpcWebServer(myGrpcService, { cors: "*" }).listen(1337, () => {});

see src/mock/server and src/index.integration.test.ts for full working example

testing

package has ~100% unit test coverage

npm test

one off tests for unary and server streaming

npm run start

npm run test:unary
npm run test:stream
1.1.0

9 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago