From 24ef9194953c27fb11a8f1ceb499e5feca11c30c Mon Sep 17 00:00:00 2001 From: Charlie McConnell Date: Wed, 21 Sep 2011 13:05:57 -0700 Subject: [PATCH 1/3] [docs] Updated examples in README.md for 0.7.x API. --- README.md | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 5737babc7..1288814e5 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,7 @@ var http = require('http'), // // Create a new instance of HttProxy to use in your server // -var proxy = new httpProxy.HttpProxy(); +var proxy = new httpProxy.RoutingProxy(); // // Create a regular http server and proxy its handler @@ -247,12 +247,14 @@ httpProxy.createServer(8000, 'localhost', options).listen(8001); // // Create an instance of HttpProxy to use with another HTTPS server // -var proxy = new httpProxy.HttpProxy(); -https.createServer(options.https, function (req, res) { - proxy.proxyRequest(req, res, { +var proxy = new httpProxy.HttpProxy({ + target: { host: 'localhost', port: 8000 - }) + } +}); +https.createServer(options.https, function (req, res) { + proxy.proxyRequest(req, res) }).listen(8002); // @@ -266,7 +268,7 @@ http.createServer(function (req, res) { ``` ### Proxying to HTTPS from HTTPS -Proxying from HTTPS to HTTPS is essentially the same as proxying from HTTPS to HTTP, but you must include `target` option in when calling `httpProxy.createServer` or instantiating a new instance of `HttpProxy`. +Proxying from HTTPS to HTTPS is essentially the same as proxying from HTTPS to HTTP, but you must include the `target` option in when calling `httpProxy.createServer` or instantiating a new instance of `HttpProxy`. ``` js var fs = require('fs'), @@ -293,15 +295,14 @@ httpProxy.createServer(8000, 'localhost', options).listen(8001); // var proxy = new httpProxy.HttpProxy({ target: { + host: 'localhost', + port: 8000, https: true } }); https.createServer(options.https, function (req, res) { - proxy.proxyRequest(req, res, { - host: 'localhost', - port: 8000 - }) + proxy.proxyRequest(req, res); }).listen(8002); // @@ -325,7 +326,7 @@ httpProxy.createServer( ``` ## Proxying WebSockets -Websockets are handled automatically when using the `httpProxy.createServer()`, but if you want to use it in conjunction with a stand-alone HTTP + WebSocket (such as [socket.io][5]) server here's how: +Websockets are handled automatically when using `httpProxy.createServer()`, but if you want to use it in conjunction with a stand-alone HTTP + WebSocket (such as [socket.io][5]) server here's how: ``` js var http = require('http'), @@ -334,26 +335,24 @@ var http = require('http'), // // Create an instance of node-http-proxy // -var proxy = new httpProxy.HttpProxy(); +var proxy = new httpProxy.HttpProxy( + target: { + host: 'localhost', + port: 8000 + }); var server = http.createServer(function (req, res) { // // Proxy normal HTTP requests // - proxy.proxyRequest(req, res, { - host: 'localhost', - port: 8000 - }) + proxy.proxyRequest(req, res); }); server.on('upgrade', function(req, socket, head) { // // Proxy websocket requests too // - proxy.proxyWebSocketRequest(req, socket, head, { - host: 'localhost', - port: 8000 - }); + proxy.proxyWebSocketRequest(req, socket, head); }); ``` From 8fc8d966c4681d514af00516b348105608e13382 Mon Sep 17 00:00:00 2001 From: Charlie McConnell Date: Wed, 21 Sep 2011 14:11:41 -0700 Subject: [PATCH 2/3] [examples] Updated examples to v0.7.x API. --- examples/websocket/latent-websocket-proxy.js | 16 +++++++--------- examples/websocket/standalone-websocket-proxy.js | 15 +++++++-------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/examples/websocket/latent-websocket-proxy.js b/examples/websocket/latent-websocket-proxy.js index 3598ca926..85a06a917 100644 --- a/examples/websocket/latent-websocket-proxy.js +++ b/examples/websocket/latent-websocket-proxy.js @@ -67,12 +67,14 @@ socket.on('connection', function (client) { // // Setup our server to proxy standard HTTP requests // -var proxy = new httpProxy.HttpProxy(); -var proxyServer = http.createServer(function (req, res) { - proxy.proxyRequest(req, res, { +var proxy = new httpProxy.HttpProxy({ + target: { host: 'localhost', port: 8080 - }) + } +}); +var proxyServer = http.createServer(function (req, res) { + proxy.proxyRequest(req, res); }); // @@ -83,11 +85,7 @@ proxyServer.on('upgrade', function (req, socket, head) { var buffer = httpProxy.buffer(socket); setTimeout(function () { - proxy.proxyWebSocketRequest(req, socket, head, { - port: 8080, - host: 'localhost', - buffer: buffer - }); + proxy.proxyWebSocketRequest(req, socket, head, buffer); }, 1000); }); diff --git a/examples/websocket/standalone-websocket-proxy.js b/examples/websocket/standalone-websocket-proxy.js index fdefa6d28..c17340509 100644 --- a/examples/websocket/standalone-websocket-proxy.js +++ b/examples/websocket/standalone-websocket-proxy.js @@ -67,12 +67,14 @@ socket.on('connection', function (client) { // // Setup our server to proxy standard HTTP requests // -var proxy = new httpProxy.HttpProxy(); -var proxyServer = http.createServer(function (req, res) { - proxy.proxyRequest(req, res, { +var proxy = new httpProxy.HttpProxy({ + target: { host: 'localhost', port: 8080 - }) + } +}); +var proxyServer = http.createServer(function (req, res) { + proxy.proxyRequest(req, res); }); // @@ -80,10 +82,7 @@ var proxyServer = http.createServer(function (req, res) { // WebSocket requests as well. // proxyServer.on('upgrade', function (req, socket, head) { - proxy.proxyWebSocketRequest(req, socket, head, { - port: 8080, - host: 'localhost' - }); + proxy.proxyWebSocketRequest(req, socket, head); }); proxyServer.listen(8081); From 549360a462c134cc2b02301070209084ec94c393 Mon Sep 17 00:00:00 2001 From: Charlie McConnell Date: Wed, 21 Sep 2011 14:53:57 -0700 Subject: [PATCH 3/3] [examples] More fixes to examples. --- examples/http/standalone-proxy.js | 2 +- examples/websocket/latent-websocket-proxy.js | 2 +- examples/websocket/standalone-websocket-proxy.js | 2 +- examples/websocket/websocket-proxy.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/http/standalone-proxy.js b/examples/http/standalone-proxy.js index e39d4b072..9ffa81757 100644 --- a/examples/http/standalone-proxy.js +++ b/examples/http/standalone-proxy.js @@ -32,7 +32,7 @@ var util = require('util'), // // Http Server with proxyRequest Handler and Latency // -var proxy = new httpProxy.HttpProxy(); +var proxy = new httpProxy.RoutingProxy(); http.createServer(function (req, res) { var buffer = httpProxy.buffer(req); setTimeout(function() { diff --git a/examples/websocket/latent-websocket-proxy.js b/examples/websocket/latent-websocket-proxy.js index 85a06a917..3112f6bf8 100644 --- a/examples/websocket/latent-websocket-proxy.js +++ b/examples/websocket/latent-websocket-proxy.js @@ -27,7 +27,7 @@ var sys = require('sys'), http = require('http'), colors = require('colors'), - websocket = require('./../vendor/websocket'), + websocket = require('../../vendor/websocket'), httpProxy = require('../../lib/node-http-proxy'); try { diff --git a/examples/websocket/standalone-websocket-proxy.js b/examples/websocket/standalone-websocket-proxy.js index c17340509..bfbc25239 100644 --- a/examples/websocket/standalone-websocket-proxy.js +++ b/examples/websocket/standalone-websocket-proxy.js @@ -27,7 +27,7 @@ var sys = require('sys'), http = require('http'), colors = require('colors'), - websocket = require('./../vendor/websocket'), + websocket = require('../../vendor/websocket'), httpProxy = require('../../lib/node-http-proxy'); try { diff --git a/examples/websocket/websocket-proxy.js b/examples/websocket/websocket-proxy.js index a1e49c61b..975fab052 100644 --- a/examples/websocket/websocket-proxy.js +++ b/examples/websocket/websocket-proxy.js @@ -27,7 +27,7 @@ var sys = require('sys'), http = require('http'), colors = require('colors'), - websocket = require('./../vendor/websocket'), + websocket = require('../../vendor/websocket'), httpProxy = require('../../lib/node-http-proxy'); try {