index.js
function createServiceHandler(handlers = {}, options = {}, shortcutType) {
  const errorHandler = options.errorHandler || defaultErrorHandler;
  const middleware = options.middleware || Array.isArray(options) && options || [];
  const mode = options.mode || FUNCTION_MODE;
  const checkArity = options.checkArity === undefined || Boolean(options.checkArity);
  const type = shortcutType || options.type || (process.env.LAMBDA_TASK_ROOT && AWS_TYPE)
    || (process.env.AzureWebJobsStorage && AZURE_TYPE) || GCLOUD_TYPE;

  if (type === AWS_TYPE) {
    // return handler function with fn(event, context, callback) signature
    return (event, context, callback) => {
      // if AWS Lambda request, convert event and context to request and response
      const req = new AWSRequest(event, context);
      const res = new AWSResponse(req, callback);
      // handle request
      handleRequest(middleware, handlers, mode, checkArity, req, res, errorHandler);
    };
  } else if (type === AZURE_TYPE) {
    // return handler function with fn(context) signature
    return (context) => {
      // if Azure request, convert context to request and response
      const req = new AzureRequest(context.req);
      const res = new AzureResponse(req, context);
      // handle request
      handleRequest(middleware, handlers, mode, checkArity, req, res, errorHandler);
    };
  } else if (type === GCLOUD_TYPE) {
    // return handler function with fn(req, res) signature
    return (req, res) => {
      // handle request
      handleRequest(middleware, handlers, mode, checkArity, req, res, errorHandler);
    };
  } else {
    throw new Error('Invalid type: ' + type)
  }
}
function createServiceHandler(handlers = {}, options = {}, shortcutType) {
  const errorHandler = options.errorHandler || defaultErrorHandler;
  const middleware = options.middleware || Array.isArray(options) && options || [];
  const mode = options.mode || FUNCTION_MODE;
  const checkArity = options.checkArity === undefined || Boolean(options.checkArity);
  const type = shortcutType || options.type || (process.env.LAMBDA_TASK_ROOT && AWS_TYPE)
    || (process.env.AzureWebJobsStorage && AZURE_TYPE) || GCLOUD_TYPE;

  if (type === AWS_TYPE) {
    // return handler function with fn(event, context, callback) signature
    return (event, context, callback) => {
      // if AWS Lambda request, convert event and context to request and response
      const req = new AWSRequest(event, context);
      const res = new AWSResponse(req, callback);
      // handle request
      handleRequest(middleware, handlers, mode, checkArity, req, res, errorHandler);
    };
  } else if (type === AZURE_TYPE) {
    // return handler function with fn(context) signature
    return (context) => {
      // if Azure request, convert context to request and response
      const req = new AzureRequest(context.req);
      const res = new AzureResponse(req, context);
      // handle request
      handleRequest(middleware, handlers, mode, checkArity, req, res, errorHandler);
    };
  } else if (type === GCLOUD_TYPE) {
    // return handler function with fn(req, res) signature
    return (req, res) => {
      // handle request
      handleRequest(middleware, handlers, mode, checkArity, req, res, errorHandler);
    };
  } else {
    throw new Error('Invalid type: ' + type)
  }
}
function createServiceHandler ( handlers = { } , options = { } , shortcutType ) { const errorHandler = options . errorHandler || defaultErrorHandler ; const middleware = options . middleware || Array . isArray ( options ) && options || [ ] ; const mode = options . mode || FUNCTION_MODE ; const checkArity = options . checkArity === undefined || Boolean ( options . checkArity ) ; const type = shortcutType || options . type || ( process . env . LAMBDA_TASK_ROOT && AWS_TYPE ) || ( process . env . AzureWebJobsStorage && AZURE_TYPE ) || GCLOUD_TYPE ; if ( type === AWS_TYPE ) { // return handler function with fn(event, context, callback) signature return ( event , context , callback ) => { // if AWS Lambda request, convert event and context to request and response const req = new AWSRequest ( event , context ) ; const res = new AWSResponse ( req , callback ) ; // handle request handleRequest ( middleware , handlers , mode , checkArity , req , res , errorHandler ) ; } ; } else if ( type === AZURE_TYPE ) { // return handler function with fn(context) signature return ( context ) => { // if Azure request, convert context to request and response const req = new AzureRequest ( context . req ) ; const res = new AzureResponse ( req , context ) ; // handle request handleRequest ( middleware , handlers , mode , checkArity , req , res , errorHandler ) ; } ; } else if ( type === GCLOUD_TYPE ) { // return handler function with fn(req, res) signature return ( req , res ) => { // handle request handleRequest ( middleware , handlers , mode , checkArity , req , res , errorHandler ) ; } ; } else { throw new Error ( 'Invalid type: ' + type ) } }
The exported function that creates the request handler
using the supplied handlers and configuration.

Returns a handler with either function(req, res) signature
or function(event, context, callback) signature.

Example:

var app = modofun(
{
authenticate: authenticate,
user: [authorize, getUser]
},
{
middleware: [logger],
errorHandler: (err, req, res) => res.status(500).send(err.message)
}
)
@public
The exported function that creates the request handler using the supplied handlers and configuration .