How to use http-proxy - 10 common examples

To help you get started, we’ve selected a few http-proxy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github minetest-mapserver / minetest-tile-server / proxy.js View on Github external
const host = process.argv[2]; // host, for example: https://pandorabox.io/map
//TODO: argument parser, more options: port, debug,e etc

console.log("Creating proxy-connection for backend @ " + host);

var httpProxy = require('http-proxy'),
    http = require("http"),
    serveStatic = require('serve-static'),
    connect   = require('connect');


var proxy = httpProxy.createProxy({
	target: host,
	secure: false
});

var app = connect()
.use("/", function(req, res, next){
	if (req.url.substring(0,3) == "/js" || req.url == "/" || req.url.substring(0,5) == "/pics" || req.url == "/search.html" || req.url == "/index.html" || req.url.substring(0,4) == "/css"){
		console.log("Local: " + req.url);
		next();
		return;
	}

	console.log("Remote: " + req.url);
	proxy.web(req, res);
})
.use(serveStatic("src/main/resources/public"));
github sillsdev / web-languageforge / test / app / node_modules / karma / lib / middleware / proxy.js View on Github external
exports.create = function(/* config */ config, /* config.proxies */ proxies,
  /* config.proxyValidateSSL */ validateSSL) {
  return createProxyHandler(new httpProxy.RoutingProxy({changeOrigin: true}),
    proxies, validateSSL, config.urlRoot);
};
github bitovi / testee / lib / _old / server / http / proxy.js View on Github external
'use strict';

var httpProxy = require('http-proxy');
var proxy = new httpProxy.RoutingProxy();

/**
 * Returns a Middleware that sets up a HTTP routing proxy to
 * another Host. Also sets the domain name which is very important
 * for virtual hosts.
 *
 * @param {Object} settings The proxy settings
 * @return {Function} The proxy middleware
 */
module.exports = function (settings) {
	return function (req, res) {
		// If routing to a server on another domain, the hostname in the request must be changed.
		req.headers.host = settings.host;
		return proxy.proxyRequest(req, res, settings);
	}
}
github divanvisagie / NARF / lib / router.js View on Github external
exports.balancer = function( nodes, port ){

	console.log( typeof nodes );

	var ev = new events.EventEmitter();
	if( !nodes || typeof nodes !== 'object' ){
		ev.emit( 'error', 'balancer() requires an address list' );
		return;
	}

	console.log( 'creating balancer on port ', port );

	httpProxy.createServer( function (req,res,proxy){


		/* on each request get a target server from the list */
		var targetServer = nodes[0];

		/* then proxy to which ever  */

		console.log( 'balancing request to:', targetServer );

		proxy.proxyRequest( req, res, targetServer );

		console.log( res );

		res.on( 'end', function( thing ){

		} );
github hoodiehq / hoodie / lib / hoodie-app.js View on Github external
});

  // on ctrl-c, stop couchdb first, then exit.
  process.on("SIGINT", function() {
    couchdb.on("stop", function() {
      process.exit(0);
    });
    couchdb.stop();
  });

  couchdb.start();
}

var hoo = new hoodie_server(name, domain, couch_url);
// start frontend proxy
var server = http_proxy.createServer(hoo);
server.listen(http_port, "0.0.0.0", function() {
  console.log("hoodie server started on port '%d'", http_port);
});

function start_workers() {
  var worker_names = [];
  var deps = package_json.dependencies;
  for(var dep in deps) {
    if(dep.substr(0, 7) == "worker-") {
      worker_names.push(dep);
    }
  }

  npm.load(function(error, npm) {
    var password = npm.config.get(name + "_admin_pass");
    // for each package_json/worker*
github beakerbrowser / homebase / lib / vhosts / proxy.js View on Github external
const express = require('express')
const chalk = require('chalk')
const proxy = require('http-proxy').createProxyServer()

module.exports.start = function (vhostCfg, config) {
  var server = express()

  server.all('*', function (req, res) {
    proxy.web(req, res, {target: vhostCfg.to})
  })

  // log
  console.log(`${chalk.bold(`Proxying`)} ${chalk.dim(`from`)} ${vhostCfg.from} ${chalk.dim(`to`)} ${vhostCfg.to}`)

  return server
}

module.exports.stop = function (vhostCfg) {
  // log
github gnieh / bluelatex / blue-web / web-server.js View on Github external
app.use(express.cookieParser('myGoodPasswordNeverKnowIt'));
    app.use(express.bodyParser());
    app.use(express.session({ secret: 'myGoodPasswordNeverKnowIt' }));

    app.use(express.favicon(path.join(__dirname, 'web_client') + '/favicon.ico'));
    app.use(express.json());
    app.use(express.urlencoded());
    app.use(express.methodOverride());
});

// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

httpProxy.createServer(function (req, res, proxy) {
    if(req.url.search("/api")>=0) {
      req.url = req.url.replace("/api","");
      proxy.proxyRequest(req, res, { host: 'bluelatex.cloudapp.net', port: 18080 });
    }else
      proxy.proxyRequest(req, res, { host: '127.0.0.1', port: app.get('port') });
}).listen(port);

http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + port);
});
github apache / apex-malhar / web / demos / app.js View on Github external
* See the License for the specific language governing permissions and
 * limitations under the License.
 */

var express = require('express');
var http = require('http');
var httpProxy = require('http-proxy');
var config = require('./config');

var machine = require('./routes/machine');
var adsdimensions = require('./routes/adsdimensions');
var fraud = require('./routes/fraud');

var app = express();

var proxy = new httpProxy.RoutingProxy();

// all environments
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);

console.log('environment: ' + app.get('env'));

app.use(express.static(__dirname + config.web.staticDir));

if ('development' == app.get('env')) {
    app.use(express.errorHandler());
}
github bbytes / proxy-etc / proxy / revproxy.js View on Github external
/*
 * Reverse Proxy
 */

var config = require('../config/config');
var collection = require('strong-store-cluster').collection('routes');
var fs = require('fs');
var httpProxy = require("http-proxy");
var proxy = new httpProxy.RoutingProxy();
var routesJson = {};

exports.init = function() {
    if (config.httpKeepAlive !== true) {
        // Disable the http Agent of the http-proxy library so we force
        // the proxy to close the connection after each request to the backend
        httpProxy._getAgent = function () {
            return false;
        };
    }
    httpProxy.setMaxSockets(config.maxSockets);
	
    function readRoutesJson(){
        fs.readFile("./config/routes.json", function (err, data) {
            if (err) {
          	  console.error("Error reading file");
github codice / ddf / ui / packages / ui / server-impl.js View on Github external
server.requestProxy = function(req, res) {
  'use strict'

  req.url = 'https://localhost:8993' + req.url
  var urlObj = URL.parse(req.url)
  req.url = urlObj.path
  // Buffer requests so that eventing and async methods still work
  // https://github.com/nodejitsu/node-http-proxy#post-requests-and-buffering
  var buffer = httpProxy.buffer(req)
  console.log('Proxying Request "' + req.url + '"')

  process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'

  proxy.proxyRequest(req, res, {
    host: urlObj.hostname,
    port: urlObj.port || 80,
    buffer: buffer,
    changeOrigin: true,
    secure: false,
    target: {
      https: true,
    },
  })
}