lib/proxy.js
function proxyRequest(req, res, rule) {
  var router,
      target,
      path;

  injectProxyHeaders(req, rule);

  // rewrite the base path of the requested URL
  path = req.url.replace(rule.regexp, rule.target.path);

  if (useGateway) {
    // for HTTP LAN proxies, rewrite the request URL from a relative URL to an absolute URL
    // also add a header that can be inspected by the unit tests
    req.url = url.parse(util.format('%s//%s:%s%s', rule.target.protocol, rule.target.host, rule.target.port, path)).href;
    req.headers['X-Forwarded-Url'] = req.url;

    // the proxy target is really the HTTP LAN proxy
    target = config.gateway;
    logger.info('proxy: %s %s --> %s:%s --> %s//%s:%s%s', req.method, req.url, config.gateway.host, config.gateway.port, rule.target.protocol, rule.target.host, rule.target.port, path);
  } else {
    target = rule.target;
    logger.info('proxy: %s %s --> %s//%s:%s%s', req.method, req.url, rule.target.protocol, rule.target.host, rule.target.port, path);
    req.url = path;
  }

  var errorCallback = function errorCallback(err, proxyRequest, proxyResponse) {
    var status = 500;
    if (proxyResponse !== undefined && proxyResponse !== null && proxyResponse.statusCode >= 400) {
      status = proxyResponse.statusCode;
    }

    logger.error('proxy: error - %s %s - %s', proxyRequest.method, proxyRequest.url, err.message);
    if( res.status && typeof res.status === 'function'  ){
        res.status(status).json({ error: status, message: err.message });
    }
  };

  // get a ProxyServer from the cache
  router = createRouter(target);

  // proxy the request
  router.web(req, res, errorCallback);
}
function proxyRequest(req, res, rule) {
  var router,
      target,
      path;

  injectProxyHeaders(req, rule);

  // rewrite the base path of the requested URL
  path = req.url.replace(rule.regexp, rule.target.path);

  if (useGateway) {
    // for HTTP LAN proxies, rewrite the request URL from a relative URL to an absolute URL
    // also add a header that can be inspected by the unit tests
    req.url = url.parse(util.format('%s//%s:%s%s', rule.target.protocol, rule.target.host, rule.target.port, path)).href;
    req.headers['X-Forwarded-Url'] = req.url;

    // the proxy target is really the HTTP LAN proxy
    target = config.gateway;
    logger.info('proxy: %s %s --> %s:%s --> %s//%s:%s%s', req.method, req.url, config.gateway.host, config.gateway.port, rule.target.protocol, rule.target.host, rule.target.port, path);
  } else {
    target = rule.target;
    logger.info('proxy: %s %s --> %s//%s:%s%s', req.method, req.url, rule.target.protocol, rule.target.host, rule.target.port, path);
    req.url = path;
  }

  var errorCallback = function errorCallback(err, proxyRequest, proxyResponse) {
    var status = 500;
    if (proxyResponse !== undefined && proxyResponse !== null && proxyResponse.statusCode >= 400) {
      status = proxyResponse.statusCode;
    }

    logger.error('proxy: error - %s %s - %s', proxyRequest.method, proxyRequest.url, err.message);
    if( res.status && typeof res.status === 'function'  ){
        res.status(status).json({ error: status, message: err.message });
    }
  };

  // get a ProxyServer from the cache
  router = createRouter(target);

  // proxy the request
  router.web(req, res, errorCallback);
}
function proxyRequest ( req , res , rule ) { var router , target , path ; injectProxyHeaders ( req , rule ) ; // rewrite the base path of the requested URL path = req . url . replace ( rule . regexp , rule . target . path ) ; if ( useGateway ) { // for HTTP LAN proxies, rewrite the request URL from a relative URL to an absolute URL // also add a header that can be inspected by the unit tests req . url = url . parse ( util . format ( '%s//%s:%s%s' , rule . target . protocol , rule . target . host , rule . target . port , path ) ) . href ; req . headers [ 'X-Forwarded-Url' ] = req . url ; // the proxy target is really the HTTP LAN proxy target = config . gateway ; logger . info ( 'proxy: %s %s --> %s:%s --> %s//%s:%s%s' , req . method , req . url , config . gateway . host , config . gateway . port , rule . target . protocol , rule . target . host , rule . target . port , path ) ; } else { target = rule . target ; logger . info ( 'proxy: %s %s --> %s//%s:%s%s' , req . method , req . url , rule . target . protocol , rule . target . host , rule . target . port , path ) ; req . url = path ; } var errorCallback = function errorCallback ( err , proxyRequest , proxyResponse ) { var status = 500 ; if ( proxyResponse !== undefined && proxyResponse !== null && proxyResponse . statusCode >= 400 ) { status = proxyResponse . statusCode ; } logger . error ( 'proxy: error - %s %s - %s' , proxyRequest . method , proxyRequest . url , err . message ) ; if ( res . status && typeof res . status === 'function' ) { res . status ( status ) . json ( { error : status , message : err . message } ) ; } } ; // get a ProxyServer from the cache router = createRouter ( target ) ; // proxy the request router . web ( req , res , errorCallback ) ; }
injects any LAN proxy servers into the request
injects any LAN proxy servers into the request