helpers/api.js
function(type,options){
  var cacheKey = type + ':' + options.host + ':' + options.port
  if(!cache[cacheKey]){
    debug('cache miss',cacheKey)
    var reqDefaults = {
      rejectUnauthorized: false,
      json: true,
      timeout:
        +process.env.REQUEST_TIMEOUT ||
        +options.timeout ||
        2147483647, //equiv to timeout max in node.js/lib/timers.js
      pool: pool
    }
    if(options.username || (config[type] && config[type].username)){
      reqDefaults.auth = {
        username: options.username || config[type].username
      }
    }
    if(options.password || (config[type] && config[type].password)){
      if(reqDefaults.auth){
        reqDefaults.auth.password = options.password || config[type].password
      } else {
        reqDefaults.auth = {
          password: options.password || config[type].password
        }
      }
    }
    var req = request.defaults(reqDefaults)
    cache[cacheKey] = extendRequest(req,type,options)
  } else {
    debug('cache hit',cacheKey)
  }
  return cache[cacheKey]
}
function(type,options){
  var cacheKey = type + ':' + options.host + ':' + options.port
  if(!cache[cacheKey]){
    debug('cache miss',cacheKey)
    var reqDefaults = {
      rejectUnauthorized: false,
      json: true,
      timeout:
        +process.env.REQUEST_TIMEOUT ||
        +options.timeout ||
        2147483647, //equiv to timeout max in node.js/lib/timers.js
      pool: pool
    }
    if(options.username || (config[type] && config[type].username)){
      reqDefaults.auth = {
        username: options.username || config[type].username
      }
    }
    if(options.password || (config[type] && config[type].password)){
      if(reqDefaults.auth){
        reqDefaults.auth.password = options.password || config[type].password
      } else {
        reqDefaults.auth = {
          password: options.password || config[type].password
        }
      }
    }
    var req = request.defaults(reqDefaults)
    cache[cacheKey] = extendRequest(req,type,options)
  } else {
    debug('cache hit',cacheKey)
  }
  return cache[cacheKey]
}
function ( type , options ) { var cacheKey = type + ':' + options . host + ':' + options . port if ( ! cache [ cacheKey ] ) { debug ( 'cache miss' , cacheKey ) var reqDefaults = { rejectUnauthorized : false , json : true , timeout : + process . env . REQUEST_TIMEOUT || + options . timeout || 2147483647 , //equiv to timeout max in node.js/lib/timers.js pool : pool } if ( options . username || ( config [ type ] && config [ type ] . username ) ) { reqDefaults . auth = { username : options . username || config [ type ] . username } } if ( options . password || ( config [ type ] && config [ type ] . password ) ) { if ( reqDefaults . auth ) { reqDefaults . auth . password = options . password || config [ type ] . password } else { reqDefaults . auth = { password : options . password || config [ type ] . password } } } var req = request . defaults ( reqDefaults ) cache [ cacheKey ] = extendRequest ( req , type , options ) } else { debug ( 'cache hit' , cacheKey ) } return cache [ cacheKey ] }
Setup a new request object
@param {string} type
@param {object} options
@return {request}
Setup a new request object