@@ -47,11 +47,14 @@ See the [demo](http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js)
47
47
<pre >
48
48
var http = require('http'),
49
49
httpProxy = require('http-proxy');
50
-
50
+ //
51
51
// Create your proxy server
52
+ //
52
53
httpProxy.createServer(9000, 'localhost').listen(8000);
53
54
55
+ //
54
56
// Create your target server
57
+ //
55
58
http.createServer(function (req, res) {
56
59
res.writeHead(200, {'Content-Type': 'text/plain'});
57
60
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)
63
66
<pre >
64
67
var http = require('http'),
65
68
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
+ //
68
73
httpProxy.createServer(function (req, res, proxy) {
74
+ //
69
75
// Put your custom server logic here
70
- proxy.proxyRequest(9000, 'localhost');
76
+ //
77
+ proxy.proxyRequest(req, res, 9000, 'localhost');
71
78
}).listen(8000);
72
79
73
80
http.createServer(function (req, res) {
@@ -81,13 +88,23 @@ See the [demo](http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js)
81
88
<pre >
82
89
var http = require('http'),
83
90
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
+ //
86
95
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
+ //
87
103
// Wait for two seconds then respond: this simulates
88
104
// performing async actions before proxying a request
105
+ //
89
106
setTimeout(function () {
90
- proxy.proxyRequest(9000, 'localhost');
107
+ proxy.proxyRequest(req, res, 9000, 'localhost', buffer );
91
108
}, 2000);
92
109
}).listen(8000);
93
110
@@ -102,15 +119,20 @@ See the [demo](http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js)
102
119
<pre >
103
120
var http = require('http'),
104
121
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
+ //
107
131
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
+ //
112
133
// Put your custom server logic here, then proxy
113
- proxy.proxyRequest(9000, 'localhost', req, res);
134
+ //
135
+ proxy.proxyRequest(req, res, 9000, 'localhost');
114
136
}).listen(8001);
115
137
116
138
http.createServer(function (req, res) {
0 commit comments