Skip to content

0.2.0

Compare
Choose a tag to compare
@bojand bojand released this 20 Feb 02:25
· 476 commits to master since this release

Adds support for multiple services, addressing #2. Should be backwards compatible.
Key changes:

  • name in constructor is now optional. If not provided all services are taken into account
  • use signature is changed to use(service, name, ...fns), where service is the service name and name is the rpc name
    • if service and name are given applies fns for that call under that service

      app.use('Greeter', 'sayHello', handler)
    • if service name is provided and matches one of the services defined in proto, but no name is provided applies the fns as middleware as service level middleware for all handlers in that service

      app.use('Greeter', mwForGreeter)
    • if service is provided and no name is provided, and service does not match any of the service names in the proto, assumes service is actually rpc call name. Uses 0th property in internal services object. Useful for protos with only one service.

      app.use('sayHello', handler)
    • if an object is provided, you can set middleware and handlers for all services

      app.use(mw1) // global for all services
      app.use('Service1', mw2) // applies to all Service1 handers
      app.use({
        Service1: {
          sayGoodbye: handler1, // has mw1, mw2
          sayHello: [ mw3, handler2 ] // has mw1, mw2, mw3
        },
        Service2: {
          saySomething: handler3 // only has mw1
        }
      })
    • if object provided but 0th key does not match any of the services in proto, assumes 0th service. Useful for protos with only one service.

      app.use({
        sayGoodbye: handler1, 
        sayHello: [ mw3, handler2 ] 
      })