Middleware
Middleware functions are functions that have access to the request object (req), the reply object (reply), and the next middleware function in the application’s request-response cycle. The next middleware function is commonly denoted by a variable named next. If you pass an error to the next function the lifecycle is aborted and the error is responded.
hemera.add({
topic: "test",
cmd: "add"
})
.use(function(req, reply, next) {
//process request
next()
})
// Pass an array of middlewares
.use([(req, reply, next) => {
next()
}])
// This is your server action
.end(function(req) => Promise.resolve(req.a + req.b))
Async / Await
You can also pass an async function.
hemera
.add({
topic: 'test',
cmd: 'add'
})
.use(async function(req, reply) {})
.end(async function(req) {})