How to use the http-proxy.RoutingProxy 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 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 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 / modules / admin-modules-configuration / server-impl.js View on Github external
/**
 * Copyright (c) Codice Foundation
 *
 * This is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either
 * version 3 of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details. A copy of the GNU Lesser General Public License is distributed along with this program and can be found at
 * .
 *
 **/
var URL = require('url'),
    httpProxy = require('http-proxy'),
    proxy = new httpProxy.RoutingProxy(),
    fs = require('node-fs'),
    path = require('path'),
    _ = require('lodash');

function stringFormat(format /* arg1, arg2... */) {
    if (arguments.length === 0) {
        return undefined;
    }
    if (arguments.length === 1) {
        return format;
    }
    var args = Array.prototype.slice.call(arguments, 1);
    return format.replace(/\{\{|\}\}|\{(\d+)\}/g, function (m, n) {
        if (m === "{{") {
            return "{";
        }
github fabiosantoscode / magicProxy / index.js View on Github external
.map(function (plugin) {
            if (!plugin.harmon) return null;
            return (config[plugin.configName || plugin.name] || [null]).map(function (op) {
                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) {
github codice / ddf / modules / admin-modules-installer / server-impl.js View on Github external
/**
 * Copyright (c) Codice Foundation
 *
 * This is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either
 * version 3 of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details. A copy of the GNU Lesser General Public License is distributed along with this program and can be found at
 * .
 *
 **/
var URL = require('url'),
    httpProxy = require('http-proxy'),
    proxy = new httpProxy.RoutingProxy(),
    fs = require('node-fs'),
    path = require('path'),
    _ = require('lodash');

function stringFormat(format /* arg1, arg2... */) {
    if (arguments.length === 0) {
        return undefined;
    }
    if (arguments.length === 1) {
        return format;
    }
    var args = Array.prototype.slice.call(arguments, 1);
    return format.replace(/\{\{|\}\}|\{(\d+)\}/g, function (m, n) {
        if (m === "{{") {
            return "{";
        }
github Bahmni / openmrs-module-bahmniapps / clinical-ui / node_modules / testacular / lib / web-server.js View on Github external
exports.createWebServer = function (baseFolder, proxies, urlRoot) {
  var staticFolder = path.normalize(__dirname + '/../static');
  var adapterFolder = path.normalize(__dirname + '/../adapter');

  var promiseContainer = {
    promise: null
  };

  var server = http.createServer(createHandler(promiseContainer,
      helper.normalizeWinPath(staticFolder), helper.normalizeWinPath(adapterFolder), baseFolder,
      new httpProxy.RoutingProxy({changeOrigin: true}), proxies, urlRoot));

  server.updateFilesPromise = function(promise) {
    promiseContainer.promise = promise;
  };

  return server;
};
github adobe-research / theseus / src / proxy / middleware-proxy.js View on Github external
/*
 middleware that proxies to http://localhost:3000/ with callbacks for filtering
 the response body

 var proxyMiddleware = require('middleware-proxy');
 var app = connect().use(proxyMiddleware(rootDir, {
   accept: function (req, contentType) { return true },
   filter: function (req, realPath, contentType, content) { return content.replace(/foo/g, 'bar') }
 }));
 */

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

var proxy = new httpProxy.RoutingProxy();

module.exports = function (root, options) {
  return function (req, res, next) {
    if (req.url.indexOf("public") !== -1) {
      var modifiedUrl = req.url.replace("/public", "");
      var fullURL = "http://" + req.headers.host + modifiedUrl;

      res.writeHead(302, { Location: fullURL });
      res.end();

      return;
    }

    var buffer = httpProxy.buffer(req);
    var _process = false;
    var _contentType;
github linemanjs / lineman / tasks / server.js View on Github external
app.configure(function() {
      app.use(express.bodyParser());
      app.use(express.static(process.cwd() + "/" + webRoot));
      if(apiProxyEnabled) {
        app.use(apiProxy(apiProxyHost, apiPort, new httpProxy.RoutingProxy()));
      }
      app.use(express.errorHandler());
    });