1.1.0-rc.3 • Published 2 months ago

@soundboks/nanogrpc-grpc-proxy v1.1.0-rc.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

gRPC HTTP -> NanoGRPC proxy

A proxy to convert gRPC requests to NanoGRPC messages. The main purpose of this project is to allow using existing industry standard tooling for gRPC with nanogrpc.

How it works

In gRPC requests are made via HTTP 2 and methods are addressed by the URI of the request.
In contrast, nanogrpc addresses methods by the crc32 hashes of the service and method names.

To do the conversion, we load the protobuf definition of the service and construct a gRPC service which proxies to a protobufjs service implementation, compatible with https://github.com/SOUNDBOKS/nanogrpc/tree/main/nanogrpc-ts.

Usage

As nanogrpc is transport-agnostic by design, the binary shipping with the project can't possibly handle all use cases.
The CLI that ships with the project, implements a very basic bluetooth, as well as serial transport that can be useful for debugging, but we expect that most consumes will want to build their own custom logic on top of the proxy, which is possible with the library version.

As a library

yarn add @soundboks/grpc-http-proxy

All you need to supply to the library is a https://github.com/SOUNDBOKS/nanogrpc/tree/main/nanogrpc-ts transport implementation and the path to a proto file containing your service definitions.

import { createGRPCserver } from "@soundboks/grpc-http-proxy"
import * as grpc from "@grpc/grpc-js"

const transport = await createTransport(...)

const grpcServer = createGRPCServer({
    nanogrpcTransport: transport,
    protoPath: "ExampleService.proto"
})

const port = 50051;
grpcServer.bindAsync(`0.0.0.0:${port}`, grpc.ServerCredentials.createInsecure(), () => {
    grpcServer.start()
});

CLI

todo