Skip to content

Commit 7a3f6df

Browse files
committed
[examples] added forward example
1 parent 04c1011 commit 7a3f6df

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Diff for: examples/forward-proxy.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var http = require('http'),
2+
httpProxy = require('../lib/http-proxy');
3+
4+
//
5+
// Target Http Server
6+
//
7+
http.createServer(function (req, res) {
8+
res.writeHead(200, { 'Content-Type': 'text/plain' });
9+
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
10+
res.end();
11+
}).listen(9000);
12+
console.log("Web server listening on port 9000");
13+
14+
//
15+
// Target Http Forwarding Server
16+
//
17+
http.createServer(function (req, res) {
18+
console.log('Receiving forward for: ' + req.url);
19+
res.writeHead(200, { 'Content-Type': 'text/plain' });
20+
res.write('request successfully forwarded to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
21+
res.end();
22+
}).listen(9001);
23+
24+
//
25+
// Basic Http Proxy Server
26+
// Forward example: send requests without care about response
27+
//
28+
httpProxy.createServer({
29+
target: 'http://localhost:9000',
30+
forward: 'http://localhost:9001'
31+
}).listen(8000)
32+
console.log("Proxy server listening on port 8000");
33+

0 commit comments

Comments
 (0)