Skip to content

Proposal for a wrapper handler in the express way #6

Description

@pjnovas

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 👍

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions