@grpc-web/proxy
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

@grpc-web/proxy npm tests coverage

gRPC Web proxy for Node.js

For Express and Connect middleware, see @grpc-web/middleware

Installation

npm install @grpc-web/proxy

Usage

This is a standalone proxy server created using @grpc-web/middleware, connect and cors packages. It can be run directly from the command line:

npx @grpc-web/proxy --target http://localhost:9090 --listen 8080

or used as a library:

const proxy = require('@grpc-web/proxy');

proxy({ target: 'http://localhost:9090' }).listen(8080);

The address http://localhost:9090 refers to the gRPC server address to which gRPC Web requests are forwarded to and 8080 refers to the port on which the proxy server is running.

It can be run in the same process as the gRPC server:

// Proxy server
proxy({ target: 'http://localhost:9090' }).listen(8080);

// gRPC server
const server = new grpc.Server();
server.addProtoService(service, implementation);
server.bind('0.0.0.0:9090', credentials);
server.start();

It also accepts a custom function which can used for configuring the HTTP/2 connection to the gRPC server:

const http2 = require('node:http2');

proxy({
  target: () => {
    return http2.connect('http://localhost:9090');
  },
}).listen(8080);

Options

  • target: gRPC server address or a custom function that returns a HTTP/2 connection to the gRPC server. See @grpc-web/middleware.
  • origin: Configures the Access-Control-Allow-Origin CORS header. See origin option in cors.
  • headers: Configures the Access-Control-Expose-Headers CORS header. See exposedHeaders option in cors.

License

MIT

Package Sidebar

Install

npm i @grpc-web/proxy

Weekly Downloads

561

Version

0.1.0

License

MIT

Unpacked Size

7 kB

Total Files

7

Last publish

Collaborators

  • marella