@@ -30,12 +30,12 @@ Let's suppose you were running multiple http application servers, but you only w
30
30
npm install http-proxy
31
31
</pre >
32
32
33
- ### How to use node-http- proxy
33
+ ### How to setup a basic proxy server
34
34
<pre >
35
35
var http = require('http'),
36
36
httpProxy = require('http-proxy');
37
37
38
- httpProxy.createServer('localhost ', '9000 ').listen(8000);
38
+ httpProxy.createServer('9000 ', 'localhost ').listen(8000);
39
39
40
40
http.createServer(function (req, res){
41
41
res.writeHead(200, {'Content-Type': 'text/plain'});
@@ -46,24 +46,36 @@ Let's suppose you were running multiple http application servers, but you only w
46
46
47
47
see the [ demo] ( http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js ) for further examples.
48
48
49
- ### How to use node-http- proxy with custom server logic
49
+ ### How to setup a proxy server with custom server logic
50
50
<pre >
51
51
var http = require('http'),
52
52
httpProxy = require('http-proxy');
53
53
54
-
55
54
// create a proxy server with custom application logic
56
55
httpProxy.createServer(function (req, res, proxy) {
57
56
// Put your custom server logic here
58
- proxy.proxyRequest('localhost ', '9000 ', req, res);
57
+ proxy.proxyRequest('9000 ', 'localhost ', req, res);
59
58
}).listen(8000);
60
59
60
+ http.createServer(function (req, res){
61
+ res.writeHead(200, {'Content-Type': 'text/plain'});
62
+ res.write('request successfully proxied: ' + req.url +'\n' + JSON.stringify(req.headers, true, 2));
63
+ res.end();
64
+ }).listen(9000);
65
+
66
+ </pre >
67
+
68
+ ### How to proxy requests with a regular http server
69
+ <pre >
70
+ var http = require('http'),
71
+ httpProxy = require('http-proxy');
72
+
61
73
// create a regular http server and proxy its handler
62
74
http.createServer(function (req, res){
63
75
var proxy = new httpProxy.HttpProxy;
64
76
proxy.watch(req, res);
65
77
// Put your custom server logic here
66
- proxy.proxyRequest('localhost', 9000 , req, res);
78
+ proxy.proxyRequest(9000, 'localhost', req, res);
67
79
}).listen(8001);
68
80
69
81
http.createServer(function (req, res){
0 commit comments