Skip to content
/ danby Public

A webserver that's also a grpc proxy for browsers

Notifications You must be signed in to change notification settings

ericbets/danby

Repository files navigation

Danby

Lightweight approach to grpc microservices in the browser. No client side lib required.

Features

  • Bare minimum configuration required, uses helmet.js to set HTTP headers to sane defaults.
  • Proxy multiple grpc microservices to this webserver, as long as they have unique grpc service names.
  • Proxy multiple routes to other http servers. Eg. "/" to localhost:3000 might map to a react app.

Usage

To install using globally, try --unsafe-perm or --allow-root why

$ npm install danby

$ danby
Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]
  --port     http port                                                [required]
  --cfg      path to toml config file
  --cert     path to ssl/tls cert file
  --key      path to ssl/tls private key 
  --webroot  path to webroot, defaults to $PWD 
  --debug    debug output to console 

Example

Let's say you want to serve some static files with access to the grpc Greeter interface. Add this into the head tag of your chosen html file:

<script src="/grpc-api"></script>

Now modify config.toml.sample to suit your local environment. Then from the console, cd into the folder you want to serve:

$ cd website
$ danby --port 3000 --cfg config.toml

Now in the browser:

//Manage call creds by setting the metadata eg. Greeter.metadata["token"] = ...
Greeter.SayHello({name: 'user'}).then(function(resp) { console.log(resp); });

In your config file, try to use absolute paths for your .proto files otherwise the paths will be relative to the folder you started the webserver in, not the config file. Or start the webserver from your config folder, and use --webroot.

Todo

  • Streaming support
  • Let user choose between Promises or Callbacks

Releases

No releases published

Packages

No packages published