new httpProxy.createProxyServer({ target: protocolPrefix + host + ':' + port, secure: false, changeOrigin: true, xfwd: true, autoRewrite: true }).on('error', function (err) { console.log(err); console.log('Listening... [press Control-C to exit]'); })
app.all('/db/*', function (req, res) { proxy.web(req, res, { target: 'https://glowing-carpet-4534.firebaseio.com/' }); });
// Create http server that leverages reverse proxy instance // and proxy rules to proxy requests to different targets http.createServer((req, res) => { logger.info(`${req.method} ${req.url}`); const target = proxyRules.match(req); if (target) { return proxy.web(req, res, { target }); } res.writeHead(500, { 'Content-Type': 'text/plain' }); res.end('The request url and path did not match any of the listed rules!'); return null; }).listen(configuration.web_server.port);
var proxyMiddleware = function(req, res, next) { if (req.url.indexOf('api') != -1) { proxy.web(req, res); } else { next(); } }
http.createServer(function (req, res) { logger.info(`Incoming request: ${req.method} ${req.url}`) logger.debug(req) try { filterRequest(req, argv) return proxy.web(req, res, { target: argv.target }) } catch (err) { logger.error(err, 'Request rejected') res.writeHead(400, { 'Content-Type': 'application/json' }) return res.end(JSON.stringify({ error: 'Request rejected' })) } })
http.createServer(function (req, res) { addresses = addresses.concat(addresses.splice(0, 1)); var target = { target: addresses }; // // Create your proxy server and set the target in the options. // var proxyServer = httpProxy.createProxyServer(target); res.writeHead(200, { 'Content-Type': 'application/json' }); res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2)); res.end(); })
proxy.on('error', function (err, req, res) { logger.error(err) res.writeHead(502, { 'Content-Type': 'application/json' }) return res.end(JSON.stringify({ error: 'Proxy error' })) })
process.nextTick(function () { app.use(function (req, res) { proxy.web(req, res, {target: host}); }); });
http .createServer(function(req, res) { let remote = HOST1; if (req.url.startsWith("/waittime")) { remote = HOST2; } proxy.web(req, res, { target: remote, secure: false }); }) .listen(process.env.PORT || 3000);
// It is important to catch any errors from the proxy or the // server will crash. An example of this is connecting to the // server when webpack is bundling proxy.on('error', function (e) { console.log('Could not connect to proxy, please try again...'); });
// log proxy data proxy.on('open', function (proxySocket) { proxySocket.on('data', function (chunk) { console.log(chunk.toString()); }); });
app.all('/build/*', function (req, res) { proxy.web(req, res, { target: 'http://127.0.0.1:3001' }); });
app.all('/socket.io*', function (req, res) { proxy.web(req, res, { target: 'http://127.0.0.1:3001' }); });
// Any requests to localhost:3000/build is proxied // to webpack-dev-server app.all('/build/*', function (req, res) { proxy.web(req, res, { target: 'http://localhost:8080' }); });