src/wrappers.js
function getHandler (method, getArgs, trans, domain = 'feathers') {
  return function (req, res, next) {
    res.setHeader('Allow', Object.values(allowedMethods).join(','));

    let params = Object.assign({}, req.params || {});
    delete params.service;
    delete params.id;
    delete params.subresources;
    delete params[0];

    req.feathers = { provider: 'rest' };
    // Grab the service parameters. Use req.feathers and set the query to req.query

    let query = req.query || {};
    let headers = fp.dissoc('cookie', req.headers || {});
    let cookies = req.cookies || {};

    params = Object.assign({ query, headers }, params, req.feathers);

    // Transfer the received file
    if (req.file) {
      params.file = req.file;
    }

    // method override
    if ((method === 'update' || method === 'patch')
      && params.query.$method 
      && params.query.$method.toLowerCase() === 'patch') {
      method = 'patch'
      delete params.query.$method
    }

    // Run the getArgs callback, if available, for additional parameters
    const [service, ...args] = getArgs(req, res, next);

    debug(`REST handler calling service \'${service}\'`, {
      cmd: method,
      path: req.path,
      //args: args,
      //params: params,
      //feathers: req.feathers
    });

    // The service success callback which sets res.data or calls next() with the error
    const callback = function (err, data) {
      debug(`${service}.${method} response:`, err || {
        status: data && data.status,
        size: data && JSON.stringify(data).length
      });
      if (err) return next(err.cause || err);

      res.data = data;

      if (!data) {
        debug(`No content returned for '${req.url}'`);
        res.status(statusCodes.noContent);
      } else if (method === 'create') {
        res.status(statusCodes.created);
      }

      return next();
    };

    trans.act({
      topic: `${domain}.${service}`,
      cmd: method,
      path: req.path,
      args: args,
      params: params,
      feathers: req.feathers
    }, callback);
  };
}
function getHandler (method, getArgs, trans, domain = 'feathers') {
  return function (req, res, next) {
    res.setHeader('Allow', Object.values(allowedMethods).join(','));

    let params = Object.assign({}, req.params || {});
    delete params.service;
    delete params.id;
    delete params.subresources;
    delete params[0];

    req.feathers = { provider: 'rest' };
    // Grab the service parameters. Use req.feathers and set the query to req.query

    let query = req.query || {};
    let headers = fp.dissoc('cookie', req.headers || {});
    let cookies = req.cookies || {};

    params = Object.assign({ query, headers }, params, req.feathers);

    // Transfer the received file
    if (req.file) {
      params.file = req.file;
    }

    // method override
    if ((method === 'update' || method === 'patch')
      && params.query.$method 
      && params.query.$method.toLowerCase() === 'patch') {
      method = 'patch'
      delete params.query.$method
    }

    // Run the getArgs callback, if available, for additional parameters
    const [service, ...args] = getArgs(req, res, next);

    debug(`REST handler calling service \'${service}\'`, {
      cmd: method,
      path: req.path,
      //args: args,
      //params: params,
      //feathers: req.feathers
    });

    // The service success callback which sets res.data or calls next() with the error
    const callback = function (err, data) {
      debug(`${service}.${method} response:`, err || {
        status: data && data.status,
        size: data && JSON.stringify(data).length
      });
      if (err) return next(err.cause || err);

      res.data = data;

      if (!data) {
        debug(`No content returned for '${req.url}'`);
        res.status(statusCodes.noContent);
      } else if (method === 'create') {
        res.status(statusCodes.created);
      }

      return next();
    };

    trans.act({
      topic: `${domain}.${service}`,
      cmd: method,
      path: req.path,
      args: args,
      params: params,
      feathers: req.feathers
    }, callback);
  };
}
function getHandler ( method , getArgs , trans , domain = 'feathers' ) { return function ( req , res , next ) { res . setHeader ( 'Allow' , Object . values ( allowedMethods ) . join ( ',' ) ) ; let params = Object . assign ( { } , req . params || { } ) ; delete params . service ; delete params . id ; delete params . subresources ; delete params [ 0 ] ; req . feathers = { provider : 'rest' } ; // Grab the service parameters. Use req.feathers and set the query to req.query let query = req . query || { } ; let headers = fp . dissoc ( 'cookie' , req . headers || { } ) ; let cookies = req . cookies || { } ; params = Object . assign ( { query , headers } , params , req . feathers ) ; // Transfer the received file if ( req . file ) { params . file = req . file ; } // method override if ( ( method === 'update' || method === 'patch' ) && params . query . $method && params . query . $method . toLowerCase ( ) === 'patch' ) { method = 'patch' delete params . query . $method } // Run the getArgs callback, if available, for additional parameters const [ service , ... args ] = getArgs ( req , res , next ) ; debug ( ` \' ${ service } \' ` , { cmd : method , path : req . path , //args: args, //params: params, //feathers: req.feathers } ) ; // The service success callback which sets res.data or calls next() with the error const callback = function ( err , data ) { debug ( ` ${ service } ${ method } ` , err || { status : data && data . status , size : data && JSON . stringify ( data ) . length } ) ; if ( err ) return next ( err . cause || err ) ; res . data = data ; if ( ! data ) { debug ( ` ${ req . url } ` ) ; res . status ( statusCodes . noContent ) ; } else if ( method === 'create' ) { res . status ( statusCodes . created ) ; } return next ( ) ; } ; trans . act ( { topic : ` ${ domain } ${ service } ` , cmd : method , path : req . path , args : args , params : params , feathers : req . feathers } , callback ) ; } ; }
A function that returns the middleware for a given method `getArgs` is a function that should return additional leading service arguments
A function that returns the middleware for a given method getArgs is a function that should return additional leading service arguments