@@ -47,11 +47,14 @@ See the [demo](http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js)
4747<pre >
4848 var http = require('http'),
4949 httpProxy = require('http-proxy');
50-
50+ //
5151 // Create your proxy server
52+ //
5253 httpProxy.createServer(9000, 'localhost').listen(8000);
5354
55+ //
5456 // Create your target server
57+ //
5558 http.createServer(function (req, res) {
5659 res.writeHead(200, {'Content-Type': 'text/plain'});
5760 res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
@@ -63,11 +66,15 @@ See the [demo](http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js)
6366<pre >
6467 var http = require('http'),
6568 httpProxy = require('http-proxy');
66-
67- // create a proxy server with custom application logic
69+
70+ //
71+ // Create a proxy server with custom application logic
72+ //
6873 httpProxy.createServer(function (req, res, proxy) {
74+ //
6975 // Put your custom server logic here
70- proxy.proxyRequest(9000, 'localhost');
76+ //
77+ proxy.proxyRequest(req, res, 9000, 'localhost');
7178 }).listen(8000);
7279
7380 http.createServer(function (req, res) {
@@ -81,13 +88,23 @@ See the [demo](http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js)
8188<pre >
8289 var http = require('http'),
8390 httpProxy = require('http-proxy');
84-
85- // create a proxy server with custom application logic
91+
92+ //
93+ // Create a proxy server with custom application logic
94+ //
8695 httpProxy.createServer(function (req, res, proxy) {
96+ //
97+ // Buffer the request so that `data` and `end` events
98+ // are not lost during async operation(s).
99+ //
100+ var buffer = proxy.buffer(req);
101+
102+ //
87103 // Wait for two seconds then respond: this simulates
88104 // performing async actions before proxying a request
105+ //
89106 setTimeout(function () {
90- proxy.proxyRequest(9000, 'localhost');
107+ proxy.proxyRequest(req, res, 9000, 'localhost', buffer );
91108 }, 2000);
92109 }).listen(8000);
93110
@@ -102,15 +119,20 @@ See the [demo](http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js)
102119<pre >
103120 var http = require('http'),
104121 httpProxy = require('http-proxy');
105-
106- // create a regular http server and proxy its handler
122+
123+ //
124+ // Create a new instance of HttProxy to use in your server
125+ //
126+ var proxy = new httpProxy.HttpProxy();
127+
128+ //
129+ // Create a regular http server and proxy its handler
130+ //
107131 http.createServer(function (req, res) {
108- // Create a new instance of HttProxy for this request
109- // each instance is only valid for serving one request
110- var proxy = new httpProxy.HttpProxy(req, res);
111-
132+ //
112133 // Put your custom server logic here, then proxy
113- proxy.proxyRequest(9000, 'localhost', req, res);
134+ //
135+ proxy.proxyRequest(req, res, 9000, 'localhost');
114136 }).listen(8001);
115137
116138 http.createServer(function (req, res) {
0 commit comments