Skip to content

hemerajs/fastify-hemera

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

fastify-hemera

Build Status styled with prettier NPM version

Fastify plugin to integrate Hemera

Install

npm install --save fastify-hemera

Register plugin

fastify.register(require('fastify-hemera'), {
  plugins: [require('hemera-mongo-store')],
  hemera: {
    name: 'test',
    logLevel: 'debug'
  },
  nats: 'nats://localhost:4242'
})

Full list of hemera plugins

Getting Started

$ docker-compose up
$ node example.js
$ curl http://localhost:3000/reply?a=33&b=22

Examples

Simple

fastify.route({
  method: 'GET',
  url: '/math/add',
  handler: (req, reply) => {
    reply.act({ topic: 'math', cmd: 'add', a: req.query.a, b: req.query.b })
  }
})

Async / Await

fastify.route({
  method: 'GET',
  url: '/math/add',
  handler: async function (req, reply) {
    let resp = await req.hemera.act({ topic: 'math', cmd: 'add', a: req.query.a, b: req.query.b })
    // access result
    resp.data
    // retain parent context
    resp = resp.context.act(...)
  }
})

Test

Testsuite makes use of hemera-testsuite, so your setup should meet it's prerequisits, esp.:

A nats server must be installed on your machine nats.io and executable as gnatsd. So add nats-server as gnatsd to your PATH as alias, link whatever works. Check if it's available:

$ gnatsd --help

Usage: nats-server [options]

[...]

Now test should succeed by running:

$ yarn test