Пример #1
0
var starProxyServer = function () {
	winston.log('info', 'Starting proxy server...');
	winston.log('info', 'Creating proxy server to %s:%s...', prod_api.host, prod_api.port);
	var prod_proxy = new httpProxy.createProxyServer({
		target: prod_api
	});
	winston.log('info', 'Creating proxy server to %s:%s...', test_api.host, test_api.port);
	var test_proxy = new httpProxy.createProxyServer({
		target: test_api
	});
	winston.log('info', 'Creating proxy server to %s:%s...', dev_api.host, dev_api.port);
	var dev_proxy = new httpProxy.createProxyServer({
		target: dev_api
	});
	winston.log('info', 'Starting http server on port %s...', proxy_api.port);
	http.createServer(function (req, res) {
		if (req.url.indexOf('env=development') > -1) {
			// redirect to dev api
			winston.log('info', 'Redirecting to dev api...');
			dev_proxy.proxyRequest(req, res);
		} else if (req.url.indexOf('env=testing') > -1) {
			// redirect to test api
			winston.log('info', 'Redirecting to test api...');
			test_proxy.proxyRequest(req, res);
		} else {
			// redirect to prod api
			winston.log('info', 'Redirecting to prod api...');
			prod_proxy.proxyRequest(req, res);
		}
	}).listen(proxy_api.port);
};
        before(function (done) {
            var proxyList = new ProxyConfigList({}, [{
                match: '*://postman-echo.com/*',
                host: proxyHost,
                port: port,
                tunnel: false
            }]);

            // @todo replace all `http-proxy` servers with server.createProxyServer
            proxyServer = new proxy.createProxyServer({
                target: 'http://postman-echo.com',
                // extra headers to be added to target request
                headers: {
                    'x-postman-proxy': 'true'
                }
            });
            proxyServer.listen(port);

            this.run({
                collection: {
                    item: {
                        request: 'http://postman-echo.com/get'
                    }
                },
                proxies: proxyList
            }, function (err, results) {
                testrun = results;
                done(err);
            });
        });
var proxyWebServer = http.createServer(function (req, res) {
	console.log('running createServer');
//  logRequest(req);
	uri = url.parse(req.url);

	var parts = req.url.split(':', 2);
	console.log('REQ HOST:'+uri.host);

	if(uri.host == TESTING_DOMAIN) {
	// we'll send this to the local server
	console.log("!!!!!!!!!!!!!!!!!!** HTTPS MAGIC **!!!!!!!!!!!!!!!!!!!!!!!!!");
//	regularProxy.proxyRequest(req, res, {
//		host: '127.0.0.1',
//		port: 9000		
//		});
	regularProxy.web(req,res,{
		target : uri.protocol+'//127.0.0.1:9000'
		});
	}
  else {
	// a regular connection to another non-local host
	console.log("!!!!!!!!!!!!!!!!!!** non magic call **!!!!!!!!!!!!!!!!!!!!!!!!!");
//	regularProxy.proxyRequest(req, res, {
//		host: uri.hostname,
//		port: uri.port || 80		
//		});
	regularProxy.web(req,res,{
		target : req.url
		});
	}
});
        before(function (done) {
            var systemProxy = function (url, callback) {
                return callback(null, undefined);
            };

            server = new proxy.createProxyServer({
                target: 'http://postman-echo.com',
                headers: {
                    'x-postman-proxy': 'true'
                }
            });
            server.listen(port);
            systemProxySpy = sinon.spy();
            server.before('web', 'stream', systemProxySpy);

            this.run({
                collection: {
                    item: {
                        request: 'http://postman-echo.com/get'
                    }
                },
                systemProxy: systemProxy
            }, function (err, results) {
                testrun = results;
                done(err);
            });
        });
Пример #5
0
var reverseProxyHandler = function (req, res) {
  var proxy = new httpProxy.createProxyServer();
  proxy.web(req, res, { target: {
      host: tomcatForwardHost,
      port: tomcatForwardPort
    }
  });
};
Пример #6
0
	http.createServer(function (req, res) {
		if (req.url.indexOf('env=development') > -1) {
			// redirect to dev api
			winston.log('info', 'Redirecting to dev api...');
			dev_proxy.proxyRequest(req, res);
		} else if (req.url.indexOf('env=testing') > -1) {
			// redirect to test api
			winston.log('info', 'Redirecting to test api...');
			test_proxy.proxyRequest(req, res);
		} else {
			// redirect to prod api
			winston.log('info', 'Redirecting to prod api...');
			prod_proxy.proxyRequest(req, res);
		}
	}).listen(proxy_api.port);
Пример #7
0
app.use(function (req, res) {
  delete req.headers.host;
  var url = req.url;
  req.url = '';
  delete res.headers['content-length'];
  proxy.web(req, res, { target: 'http:/' + url });
});
Пример #8
0
 setTimeout(function () {
   proxy.proxyRequest(req, resp, {
     host: host,
     port: port,
     buffer: buffer
   });
 }, process.env.ARTIFICIAL_CORS_DELAY);
Пример #9
0
  big.start({ port: 8888 }, function(){
    debug('Started');

    /*
    mesh.emitter.on('loadbalancer::addSite', function (opts) {
      proxyTable[opts.domain] = opts;
      
      console.log("ADDING SITE");
    })
    */
    console.log(big.resource.eventTable)

    var proxy = new httpProxy.createProxyServer();
    http.createServer(function (req, res) {
      var host = req.headers.host.split(":");
      host = host[0];
      debug(host, proxyTable);

      if (typeof proxyTable[host] !== "undefined") {
        var target = "http://" + proxyTable[host].host + ":" + proxyTable[host].port;
        proxy.web(req, res, {
          target: target
        });
      } else {
        res.end('invalid proxy target: ' + host);
      }

    }).listen(7777);

    debug('Load balancer started at 7777');

  });
Пример #10
0
 return function (req, res, next) {
     if (req.url.match(new RegExp('^\/stubs\/'))) {
         proxy.web(req, res, { target: host + ':' + port});
     } else {
         next();
     }
 }
Пример #11
0
 var server = https.createServer(config.proxy.https(),function(req,res) {
   if(/^\/system\/[a-zA-Z0-9_]+/.test(req.url)) {
     wsroute(req,res);
   } else {
     frontproxy.web(req,res);
   }
 });
Пример #12
0
			app.all("*", function(req, res) {
				proxy.web(req, res, contentBase, function(err) {
					var msg = "cannot proxy to " + contentBase.target + " (" + err.message + ")";
					this.io.sockets.emit("proxy-error", [msg]);
					res.statusCode = 502;
					res.end();
				}.bind(this));
			}.bind(this));
Пример #13
0
		app.use(function(req,res,next) {
			var from = new RegExp("^\\" + self.reverseProxyConfig.from);
			if (from.test(req.url)) {
				proxy.web(req, res, { target: self.reverseProxyConfig.target });
			} else {
				next();
			}
		});
Пример #14
0
app.use(function(req, res, next) {
	if (req.url.match(new RegExp('^\/appcv\/'))) {
		console.log('proxy to: 61.186.243.102');
		proxy.web(req, res);
	} else {
		next();
	}
});
Пример #15
0
function route_api(data, url_parts, req, json_callback) {
    // TODO: Error handling
    var api_version = url_parts[2];
    if (api_version == 'v1') {
      var api1 = url_parts[3];
      switch (api1)
      {
      case 'block':
        var api2 = url_parts[4];
        var parameter = url_parts[5];
        switch (api2)
        {
        case 'hash':
          route_api_query(data, {'currency': data['currency_api'], 'method': 'block_hash', 'params': { 'hash': parameter }}, json_callback);
          break;
        case 'index':
          route_api_query(data, {'currency': data['currency_api'], 'method': 'block_index', 'params': { 'index': Number(parameter) }}, json_callback);
          break;
        case 'height':
          route_api_query(data, {'currency': data['currency_api'], 'method': 'block_height', 'params': { 'height': Number(parameter) }}, json_callback);
          break;
        }
        break;
      case 'tx':
        var api2 = url_parts[4];
        var parameter = url_parts[5];
        switch (api2)
        {
        case 'hash':
          route_api_query(data, {'currency': data['currency_api'], 'method': 'tx_hash', 'params': { 'hash': parameter }}, json_callback);
          break;
        case 'index':
          route_api_query(data, {'currency': data['currency_api'], 'method': 'tx_index', 'params': { 'index': Number(parameter) }}, json_callback);
          break;
        case 'push':
          break;
        }
        break;
      case 'address':
        var api2 = url_parts[4];
        var address = url_parts[5];
        var confirmations = (req.param('confirmations') !== undefined) ? Number(req.param('confirmations')) : 1;
        switch (api2)
        {
        case 'balance':
          route_api_query(data, {'currency': data['currency_api'], 'method': 'address_balance', 'params': { 'address': address, 'confirmations': confirmations }}, json_callback);
          break;
        case 'unspent':
          route_api_query(data, {'currency': data['currency_api'], 'method': 'address_unspent', 'params': { 'address': address, 'confirmations': confirmations }}, json_callback);
          break;
        }
        break;
      }
    } else if (api_version == 'raw') {
      // "raw" api, proxy to actual bkchaind server
      proxy.web(req, res, { target: get_raw_api_url(data['currency_api']) });
    }
}
Пример #16
0
			app.all(proxyOptions.path, function (req, res) {
				if(typeof proxyOptions.rewrite === "function") proxyOptions.rewrite(req, proxyOptions);
				proxy.web(req, res, proxyOptions, function(err){
					var msg = "cannot proxy to " + proxyOptions.target + " (" + err.message + ")";
					this.io.sockets.emit("proxy-error", [msg]);
					res.statusCode = 502;
					res.end();
				}.bind(this));
			}.bind(this));
app.use(function(req, res, next) {
  if (req.url.match(new RegExp('^\/canteen-orders\/api\/'))) {
    console.log('proxy to: 10.108.10.174');
    proxy.web(req, res, {
      target: 'http://10.108.1.198:8888'
    }, function(err) {
      console.error(err);
    });
  } else if (req.url.match(new RegExp('^\/canteen-restaurants\/api\/'))) {
    console.log('proxy to: 10.108.10.174');
    proxy.web(req, res, {
      target: 'http://10.108.1.198:8887'
    }, function(err) {
      console.error(err);
    });
  } else {
    next();
  }
});
Пример #18
0
function proxyToRouterSSL(req, res) {
	// FIX: header info may be lost for ssl behind a load balancer...
	req.headers['x-forwarded-proto'] = "https";
	proxy.web(req, res, {
		target: {
			host: '127.0.0.1',
			port: drone_config.ports.router
		}
	});
}
Пример #19
0
 return function apiProxyHandler(req, res, next) {
   if (req.url.match(pattern)) {
     req.url = '/webapi/1/' + req.url.split('/').slice(2).join('/'); // remove the '/api' part
     return proxy.proxyRequest(req, res, {
       target: 'http://127.0.0.1:9292'
     });
   } else {
     return next();
   }
 };
Пример #20
0
function forwardSocket(req, socket, head) {
	//
	// forward to the router
	//
	proxy.ws(req, socket, head, {
		target: {
			host: '127.0.0.1',
			port: drone_config.ports.router
		}
	});
}
Пример #21
0
	Object.keys(setup).forEach(function(name) {
		var config = setup[name] || {},
		    port = that.nextPort++;

		config.target = config.target || {};
		config.target.hostname = "127.0.0.1"; // localhost
		config.target.port = port;
		var proxy = new httpProxy.createProxyServer(config);
		proxy.on("error", function(err, socket, res) {
			proxylogger("Error proxying to %s: %s", name, err);
			if (res.writeHead)
				res.send(500, nodeutil.format(PROXY_ERR, name));
			else if (socket.close)
				socket.close();
		});
		result[name] = {
			port: port,
			proxy: proxy,
		};
		proxylogger("Creating proxy config: %s --proxy--> port :%s ", name, port);
	});
Пример #22
0
function proxyToRouter(req, res) {
	//
	// forward to the router
	//
	proxy.web(req, res, {
		target: {
			host: '127.0.0.1',
			port: drone_config.ports.router
		}
	});

}
Пример #23
0
function proxySocket(req, socket, head) {

	var host = req.headers.host || false;
	// don't continue if there is no host
	if( !host ) return res.end();

	// get the port for the requested host
	var target = hosts.find( host );
	// FIX: http-proxy seems to work better with addresses (for now)
	target = "http://localhost:"+target.port;
	proxy.ws(req, socket, head, { target: target });

}
Пример #24
0
    return function(req, res, next) {
        if (req.url.indexOf('/__api__/proxy/') === 0 || req.url.indexOf('/proxy/') === 0) {
            var url = decodeURIComponent(req.url.replace(new RegExp('(/__api__)?/proxy/'), ''));
            var parsed_url = parse_url(url);
            var targetHost = parsed_url.protocol + '//' + parsed_url.host;

            // rebuild the location header, so browsers can follow them
            proxy.once('proxyRes', function (proxyRes, req, res) {
                if (proxyRes.headers.location) {
                    var parsed_location = parse_url(proxyRes.headers.location);
                    var new_proxy_url;
                    if (parsed_location.host) {
                        new_proxy_url = parsed_location.href;
                    } else {
                        // if server responded with a relative/absolute url (no hostname),
                        // fill in the hostname ourselves.
                        new_proxy_url = targetHost + parsed_location.path;
                    }
                    proxyRes.headers.location = 'http://' + req.headers.host + '/proxy/' + encodeURIComponent(new_proxy_url);
                }
            });

            req.url = url;
            proxy.web(req, res, { target: targetHost },
                function error(err, req, res) {
                    options.emitter.emit('error', 'Proxy error for url: ' + url, err.message);
                    // For connection errors, err.code will be a string like 'ENOTFOUND'
                    // Let's ensure code is numeric and >= 100, as that is what
                    // response's writeHead expects.
                    // TODO: perhaps it would be best to return HTTP 502 in the
                    // case that proxying fails?
                    res.writeHead(err.code && typeof err.code == 'number' && err.code >= 100 ? err.code : 500);
                    res.end(err.message);
                });
        }
        else {
            next();
        }
    };
http.createServer(function(req, res) {

	var uri = url.parse(req.url).pathname, filename = path.join(PROJECT_DIRECTORY, uri);
   
	if (!fs.existsSync(filename)) {
		// no local file, so we 'll try and grab it remotely!
		console.log("!!!!!!!!!!!!!!!!!! FORWARD MAGIC "+req.headers.host+uri);

		// if you want to simulate files not working.
		// res.writeHead(404, {"Content-Type": "text/plain"});
		// res.write("404 Local File Not Found - Additionally \"Host:\" Header Missing - forwarding not possible.\n");
		// res.end();
		// return
		
		// for now we'll do all our requests http (we still need a way to know if origin request was http or https)
// *** 201352 -> new API for httpProxy
//		FILEMISSINGproxy.proxyRequest(req, res, {
//		console.log(req.connection);
		
//!!! THIS DOES NOT CURRENTLY ADEQUATELY FORWARD SECURE REQUESTS
		var target = (req.connection.encrypted ? "https://" : "http://")+req.headers.host+":80"+uri;
		console.log(target);
		FILEMISSINGproxy.web(req,res,{
			target : target,
			secure : false
			});
			
		return;
		}
	
	if (fs.statSync(filename).isDirectory()) filename += '/index.html';
 
    fs.readFile(filename, "binary", function(err, file) {
		if(err) {        
			res.writeHead(500, {"Content-Type": "text/plain"});
			res.write(err + "\n");
			res.end();
			return;
			}
	
		var content_type = mime.lookup(filename); 
		if ((content_type == "text/html") || (content_type == "text/css")) {
			// tell the webbrowser the files we're working on are utf8 by appending to Content-Type
			content_type = content_type + "; charset=utf-8";
			}
		res.writeHead(200, {"Content-Type": content_type});
		res.write(file, "binary");
		res.end();
		});
	}).listen(parseInt(localWebserverPort));
Пример #26
0
    var apiProxy = function apiProxy(pattern, host, port) {
      var proxy = new httpProxy.createProxyServer();

      return function apiProxyHandler(req, res, next) {
        if (req.url.match(pattern)) {
          req.url = '/webapi/1/' + req.url.split('/').slice(2).join('/'); // remove the '/api' part
          return proxy.proxyRequest(req, res, {
            target: 'http://127.0.0.1:9292'
          });
        } else {
          return next();
        }
      };
    };
Пример #27
0
      freeport((poxyErr, proxyPort) => {
        if (poxyErr) {
          throw poxyErr;
        }

        const routingProxy = new httpProxy.createProxyServer(); // eslint-disable-line
        proxy = http.createServer(basic, (req, res) => {
          routingProxy.web(req, res, {
            target: url,
          });
        });
        proxy.listen(proxyPort);
        proxyUrl = `http://${host}:${proxyPort}/`;
        done();
      });
Пример #28
0
			app.all(proxyOptions.path, function (req, res) {
				if(typeof proxyOptions.rewrite === 'function') proxyOptions.rewrite(req, proxyOptions);
				if (proxyOptions.host) {
					req.headers.host = proxyOptions.host;
				}
				proxy.web(req, res, proxyOptions, function(err){
					var msg = "cannot proxy to " + proxyOptions.target + " (" + err.message + ")";
					this.io.sockets.emit("proxy-error", [msg]);
					res.statusCode = 502;
					res.end();
				}.bind(this));
				if (proxyOptions.configure) {
					proxyOptions.configure(proxy);
				}
			}.bind(this));
Пример #29
0
    http.createServer(function (req, res) {
      var host = req.headers.host.split(":");
      host = host[0];
      debug(host, proxyTable);

      if (typeof proxyTable[host] !== "undefined") {
        var target = "http://" + proxyTable[host].host + ":" + proxyTable[host].port;
        proxy.web(req, res, {
          target: target
        });
      } else {
        res.end('invalid proxy target: ' + host);
      }

    }).listen(7777);
Пример #30
0
app.use(function(req, res, next){
    if (maintenance){
        res.render('error', {
            page: "maintenance"
        });
    } else {
        proxy.web(req, res, {
            target: "http://127.0.0.1:3001"
        }, function (e) {
            var err = new Error("Service Unavailable");
            err.status = 503;
            next(err);
        });
    }
});