How to use the http-proxy.HttpProxy 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 FriendCode / loadfire / lib / patterns / base.js View on Github external
BasePattern.prototype.handleWs = function (req, socket, head) {
    var backend = this.pickTreat(req);

    console.log('WEBSOCKET', backend);

    // Proxy the WebSocket request to the backend
    var proxy = new httpProxy.HttpProxy({
        target: {
            host: backend.host,
            port: backend.port
        }
    });
    var buffer = httpProxy.buffer(socket);
    proxy.proxyWebSocketRequest(req, socket, head, buffer);
};
github easysoa / EasySOA / easysoa-web / js / web.js View on Github external
url = url.replace('localhost', '127.0.0.1');
   // XXX URL fix (pb caused by Connect/Express?)
   if (url.indexOf('servicefinder') == -1) {
    url = url.replace('/http://127.0.0.1:'+settings.webPort, '');
   }
   return url;
}

function urlFixer(request, response, next) {
   request.url = fixUrl(request.url);
   next();
}

/* Web server */

var tunnelProxy = new httpProxy.HttpProxy();

var webServer = express.createServer();

webServer.configure(function(){
  //  webServer.use(express.logger({ format: ':method :url' }));
    webServer.use(express.cookieParser());
    webServer.use(express.session({ secret: "easysoa-web" }));
    webServer.use(express.bodyParser());
    webServer.use(urlFixer);
    webServer.use(easysoaAuth.authFilter);
    webServer.use(webServer.router);
    webServer.use(express.favicon(__dirname + '/favicon.ico', { maxAge: 0 }));
    webServer.use(express.static(__dirname + '/' + settings.webRoot));
    webServer.use(express.directory(__dirname + '/' + settings.webRoot));
});
github basisjs / basisjs-tools / lib / server / modules / http / rewrite.js View on Github external
req.rewritten.push({
            host: loc.host,
            url: loc.url
          });

          loc = location;
        }
        else
        {
          if (args.indexOf('P') !== -1)
          {
            if (!rule.proxy)
            {
              // lazy proxy creation for rule
              rule.proxy = new httpProxy.HttpProxy({
                changeOrigin: true,
                target: {
                  host: location.hostname,
                  port: location.port || (location.protocol == 'https:' ? 443 : 80),
                  https: location.protocol == 'https:'
                },
                enable: {
                  xforward: false
                }
              });

              rule.proxy.on('proxyError', function(err){
                logWarn('proxy', err);

                try {
                  res.writeHead(500, { 'Content-Type': 'text/plain' });
github szimek / xmpp-chat / server.js View on Github external
// Basic server to serve static assets from /public folder
// with a proxy for XMPP server BOSH interface

var util = require('util'),
    express = require('express'),
    partials = require('express-partials'),
    httpProxy = require('http-proxy');

var app = express(),
    proxy = new httpProxy.HttpProxy({
        target: {
            host: 'localhost',
            port: 5280          // Port of XMPP server
        }
    });

app.configure(function() {
    app.use(express.static(__dirname));
    app.use(partials());
    app.use(express.bodyParser());
    app.use(express.cookieParser());
    app.use(express.session({secret: 'f7cd7374c2851fb727582bf'}));
});

app.set('view engine', 'ejs');
github modjs / mod / lib / utils / proxy.js View on Github external
fs.createReadStream(file).pipe(res);
                        }else{
                            next();
                        }
                    }
                },
                config: proxyOption
            });

        } else if(proxyOption.host){

            proxyOption.rules = exports.processRewrites(proxyOption);

            exports.registerProxy({
                // Create an instance of HttpProxy to use with another HTTP server
                server: new httpProxy.HttpProxy({
                    // options for proxy target
                    target: proxyOption,
                    // changes the origin of the host header to the target URL
                    changeOrigin: proxyOption.changeOrigin,
                    enable : {
                        xforward: proxyOption.xforward // enables X-Forwarded-For
                    },
                    timeout: proxyOption.timeout
                }),
                config: proxyOption
            });
        }

        logger.log( 'proxy', 'Route [' + proxyOption.location + " -> " + (proxyOption.host || proxyOption.file || proxyOption.root || proxyOption.alias) + ']' );
    });
}
github yuanyan / hp / lib / proxy.js View on Github external
fs.createReadStream(file).pipe(res);
                        }else{
                            next();
                        }
                    }
                },
                config: proxyOption
            });

        } else if(proxyOption.host){

            proxyOption.rules = exports.processRewrites(proxyOption);

            exports.registerProxy({
                // Create an instance of HttpProxy to use with another HTTP server
                server: new httpProxy.HttpProxy({
                    // options for proxy target
                    target: proxyOption,
                    // changes the origin of the host header to the target URL
                    changeOrigin: proxyOption.changeOrigin,
                    enable : {
                        xforward: proxyOption.xforward // enables X-Forwarded-For
                    },
                    timeout: proxyOption.timeout
                }),
                config: proxyOption
            });
        }

        exports.logger.log('Route [' + proxyOption.location + " -> " + (proxyOption.host || proxyOption.file || proxyOption.root || proxyOption.alias) + ']' );
    });
};
github apache / apex-malhar / front / server.js View on Github external
var app = express();
var ejs = require('ejs');
var fs = require('graceful-fs');
var path = require('path');
var Hash = require('hashish');
var httpProxy = require('http-proxy');
var browserify = require('browserify');
var util = require('./util');

// Dev configuration
var config = require('./config');
// Package
var pkg = require('./package.json');

// Set up the proxy that goes to the gateway
var proxy = new httpProxy.HttpProxy({
    target: {
        host: config.gateway.host,
        port: config.gateway.port
    }
});

// Set logger
app.use(express.logger());

// Configure the app
app.configure(function(){

    // Set rendering engine to EJS
    app.engine('html', ejs.renderFile);
    app.set('view engine', 'ejs');
github basisjs / basisjs / tools / server / server.js View on Github external
var app = http.createServer(function(req, res){
    var location = url.parse(req.url, true, true);
    var pathname = location.pathname.slice(1);

    //proxy request if nececcary
    for (var i = 0, rule; rule = rewriteRules[i]; i++)
    {
      if (rule.re.test(pathname))
      {
        if (!proxy)
        {
          proxy = new httpProxy.HttpProxy({
            target: {
              host: 'localhost',
              port: 80
            }
          });
        }

        //console.log(re);
        proxy.proxyRequest(req, res);
        return;
      }
    }

    //
    var filename = path.normalize(BASE_PATH + location.pathname);
    var fnKey = normPath(filename);
github zentooo / node-http-proxy-selective / lib / http-proxy-selective.js View on Github external
function proxy(req, res, url) {
  var proxy = new httpProxy.HttpProxy(req, res);
  proxy.proxyRequest(url.port || 80, url.hostname, req, res);
}