lib/connection.js
function runBeforeHooks(req, method, config, conn, cb){
  var httpMethod = conn.connection.methods[method];
  
  async.eachSeries(conn.connection.hooks.before, function (hook, nextHook) {
    hook(req, httpMethod, config, conn, function (err) {
      if(err) {
        return nextHook(err);
      }
      if(!_.isEmpty(config.endpoint) && typeof req === 'undefined'){
        req = request[httpMethod](config.endpoint);
        setRequestHeaders(conn.connection, req);
      }
      nextHook();
    });
  }, function (err) {
    if(err) {
      return cb(err);
    }
    cb(null, req);
  });
}
function runBeforeHooks(req, method, config, conn, cb){
  var httpMethod = conn.connection.methods[method];
  
  async.eachSeries(conn.connection.hooks.before, function (hook, nextHook) {
    hook(req, httpMethod, config, conn, function (err) {
      if(err) {
        return nextHook(err);
      }
      if(!_.isEmpty(config.endpoint) && typeof req === 'undefined'){
        req = request[httpMethod](config.endpoint);
        setRequestHeaders(conn.connection, req);
      }
      nextHook();
    });
  }, function (err) {
    if(err) {
      return cb(err);
    }
    cb(null, req);
  });
}
function runBeforeHooks ( req , method , config , conn , cb ) { var httpMethod = conn . connection . methods [ method ] ; async . eachSeries ( conn . connection . hooks . before , function ( hook , nextHook ) { hook ( req , httpMethod , config , conn , function ( err ) { if ( err ) { return nextHook ( err ) ; } if ( ! _ . isEmpty ( config . endpoint ) && typeof req === 'undefined' ) { req = request [ httpMethod ] ( config . endpoint ) ; setRequestHeaders ( conn . connection , req ) ; } nextHook ( ) ; } ) ; } , function ( err ) { if ( err ) { return cb ( err ) ; } cb ( null , req ) ; } ) ; }
Run all hook functions defined on `connection.hooks.before`.
Used to modify request properties before running the actual request.
Creates a SuperAgent Request object as soon as `config.endpoint` is defined by one of the hooks.

@note When using your own hooks, please ensure the first hook in the chain defines `config.endpoint` properly, so
SuperAgent Request object can be initialized with the correct HTTP endpoint.

@param {Request} req - SuperAgent HTTP Request object
@param {String}  method - The model method
@param {Object}  config - configuration object used to hold request-specific configuration. this is used to avoid polluting the connection's own configuration object.
@param {Object}  conn - connection configuration object:
- {Object} connection - Waterline connection configuration object
- {String} collection - collection name. appended to API pathname.
For example, given the api `http://localhost:8080/api/v1`,
a collection named `user` will resolve to `http://localhost:8080/api/v1/user`.
- {Object} options - query options object. contains query conditions (`where`), sort, limit etc. as per Waterline's API.
- {Array<Object>} values - values of records to create.
@param {Function} cb - function with error (Error object, or a falsy value if finished succesfully) and req (SuperAgent Request object, or undefined if error is not falsy) that is called when runBeforeHooks finishes
Run all hook functions defined on connection . hooks . before . Used to modify request properties before running the actual request . Creates a SuperAgent Request object as soon as config . endpoint is defined by one of the hooks .