Hey there, this lib is awesome!, it's exactly what I was looking for.
So I wanted to push a little more forward the handler func to express like and I made a wrapper on my project like this:
// file: chain.js
import Series from 'hapi-next';
export default function() {
let funcs = Array.prototype.slice.call(arguments);
return function (request, reply){
(new Series(funcs)).execute(request, reply);
}
}
And at my controller I have:
// file: eventController.js
import chain from './chain';
const fetchEvent = async (request, reply) => { /*...*/ reply.next() /*...*/ }
const isEventOwner = async (request, reply) => { /*...*/ reply.next() /*...*/ }
exports.remove = {
auth: 'simple',
// Below is where I use it
handler: chain(fetchEvent, isEventOwner, async (request, reply) => {
await request.event.remove();
return reply().code(204);
})
};
The main idea is to use that function chain as the hapi handler in the exact same way as express.
I think it would be awesome to have a function wrapper in that way at the core of this library, what do you think?
Thanks again for this piece of work 👍
Hey there, this lib is awesome!, it's exactly what I was looking for.
So I wanted to push a little more forward the
handlerfunc to express like and I made a wrapper on my project like this:And at my controller I have:
The main idea is to use that function
chainas the hapi handler in the exact same way as express.I think it would be awesome to have a function wrapper in that way at the core of this library, what do you think?
Thanks again for this piece of work 👍