hexnut-handle
is a hexnut middleware for creating simple message and connection handlers. It can also be used with hexnut-client
.
npm i hexnut-handle
handle.connect(middlewareFunction)
const handle = require('hexnut-handle');
app.use(handle.connect(ctx => {
ctx.send('Welcome!');
}));
handle.message(middlewareFunction)
const handle = require('hexnut-handle');
app.use(handle.message(ctx => {
ctx.send(`You sent: ${ctx.message}`);
}));
handle.matchMessage(messageRecogniserFunction, middlewareFunction)
const handle = require('hexnut-handle');
const messageRecogniser = msg => msg === 'Hello world';
app.use(handle.matchMessage(messageRecogniser, ctx => {
ctx.send('Hello to you too!');
}));
handle.closing(middlewareFunction)
const handle = require('hexnut-handle');
app.use(handle.closing(ctx => {
// Do some cleanup here if necessary.
}));