Permalink
Browse files

Simple reverse proxy server

  • Loading branch information...
1 parent 045c1d2 commit 79a86631e28e92211f5e8ef7eb87cdd13ec23b5a @pquerna committed Sep 5, 2010
Showing with 24 additions and 0 deletions.
  1. +24 −0 limiting_concurrency/server_nolimit.js
@@ -2,3 +2,27 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND. See the accompanying
* LICENSE file.
*/
+
+var http = require('http');
+var sys = require('sys');
+var destination = "nodejs.org";
+
+http.createServer(function(req, res) {
+ var proxy = http.createClient(80, destination);
+ var preq = proxy.request(req.method, req.url, req.headers);
+
+ preq.on('response', function(pres) {
+ res.writeHead(pres.statusCode, pres.headers);
+ sys.pump(pres, res);
+ pres.on('end', function() {
+ preq.close();
+ res.close();
+ })
+ });
+ req.on('data', function(chunk) {
+ preq.write(chunk, 'binary');
+ });
+ req.on('end', function() {
+ preq.end();
+ });
+}).listen(8080);

0 comments on commit 79a8663

Please sign in to comment.