How to use the http-proxy.createServer function in http-proxy

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 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 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 / couchdb-fauxton / devserver.js View on Github external
const runWebpackServer = function () {
  const proxy = httpProxy.createServer({
    secure: false,
    changeOrigin: true,
    target: settings.proxy.target
  });

  proxy.on('proxyRes', function (proxyRes) {
    if (proxyRes.headers['set-cookie']) {
      proxyRes.headers['set-cookie'][0] = proxyRes.headers["set-cookie"][0].replace('Secure', '');
    }
  });

  proxy.on('error', function () {
    // don't explode on cancelled requests
  });

  const options = {
github http-auth / http-auth / examples / example_proxy.js View on Github external
var httpProxy = require('http-proxy');


/**
 * Requesting new authentication instance.
 */
var basic = auth({
	authRealm : "Private area.",
	authList : ['mia:supergirl', 'Carlos:test456', 'Sam:oho'],
   proxy : true
});

/**
 * Create a proxy server with custom application logic.
 */
httpProxy.createServer(function(req, res, proxy) {
	basic.apply(req, res, function() {
		proxy.proxyRequest(req, res, {
			host : 'localhost',
			port : 9000
		});
	});
}).listen(8000);

/**
 * Destination server.
 */
http.createServer(function(req, res) {
	res.end('request successfully proxied!');
}).listen(9000);

// Log url.
github ericflo / irlmoji / server.js View on Github external
utils.readEnv();

var NODE_ENV = process.env['NODE_ENV'];
var PROD = NODE_ENV === 'production';
var IRLMOJI_API_BASIC_USER = process.env['IRLMOJI_API_BASIC_USER'];
var IRLMOJI_COOKIE_SECRET = process.env['IRLMOJI_COOKIE_SECRET'];
var IRLMOJI_PROXY_BACKEND_URL = process.env['IRLMOJI_PROXY_BACKEND_URL'];
var TWITTER_CONSUMER_KEY = process.env['TWITTER_CONSUMER_KEY'];
var TWITTER_CONSUMER_SECRET = process.env['TWITTER_CONSUMER_SECRET'];
var TWITTER_CALLBACK_URL = process.env['TWITTER_CALLBACK_URL'];
var FRONTEND_URL = process.env['FRONTEND_URL'];
var API_URL = process.env['API_URL'];

var PAGE_TEMPLATE = fs.readFileSync('frontend/page.html');
var PROXY = httpProxy.createServer({target: IRLMOJI_PROXY_BACKEND_URL});
var HASH_CACHE = {};

function getHashForFilename(fn) {
  var resp = HASH_CACHE[fn];
  if (resp) {
    return resp;
  }
  var hsh = crypto.createHash('sha1');
  hsh.update(fs.readFileSync(fn));
  HASH_CACHE[fn] = hsh.digest('hex');
  return HASH_CACHE[fn];
}

function fixConnectCookieSessionHandler(req, res, next) {
  // This user won't have to log in for a year
  req.session.cookie.maxAge = 365 * 24 * 60 * 60 * 1000;
github nordnet / nordnet-next-api / examples / client / webpack / proxy.js View on Github external
var httpProxy = require('http-proxy');
var config = require('./../package.json').config.proxy_server;

//
// Creates the proxy server listening on port 9090 that forwards requests to nExt API test server
//
httpProxy.createServer({
  secure: false,
  changeOrigin: true,
  target: config.forward_to,
}).listen(config.port);
github fabiosantoscode / magicProxy / index.js View on Github external
if (pluginAppliesHere(plugin, op, req)) {
                    return plugin.harmon(req, res, op);
                }
            })
        })

    // Remove falsy values and empty arrays, making it
    // possible to return an array of actions, and letting
    // plugins cancel
    return _.compact(_.flatten(result));
}

var proxy = new httpProxy.RoutingProxy()

/* Listen to HTTP requests */
var proxyServer = httpProxy.createServer(function staticPlugins(req, res, next) {
    /* Check if any plugin wishes to intercept and respond to the request immediately */
    if (!immediateResponse(req, res)) {
        return next()
    }
}, function harmonPlugins(req, res, next) {
    var harmonActions = harmonResponse(req, res);

    if (harmonActions.length) {
        return harmon(null, harmonActions)(req, res, next)
    } else {
        return next()
    }
}, function (req, res, next) {
    var parsed = url.parse(req.url)

    // Protect Wordpress, Wikipedia and other sites from their naiveté
github leeluolee / puer / src / util / proxy.js View on Github external
function createServer(ssl, notPrepend){
  var options = { secure: false }

  if( ssl ) options.ssl = {
    key: fs.readFileSync(libPath.join( __dirname, '../resource/cert', 'proxy-key.pem'), 'utf8'),
    cert: fs.readFileSync(libPath.join( __dirname, '../resource/cert', 'proxy-cert.pem'), 'utf8')
  }


  return httpProxy.createServer( options )

}