Skip to content

Instantly share code, notes, and snippets.

@tralamazza
Created July 26, 2011 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tralamazza/1106179 to your computer and use it in GitHub Desktop.
Save tralamazza/1106179 to your computer and use it in GitHub Desktop.
dummy nc web server
{ echo -ne "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type: text/plain\r\n\r\n"; node -v; } | nc.traditional -l -p 8001
@tralamazza
Copy link
Author

First run the little nc script (nc.traditional for ubuntu)

Create a simple http proxy:

var http = require('http'),
  httpProxy = require('http-proxy');

var proxy = new httpProxy.HttpProxy();

proxy.on('proxyError', function(err, req, res) {
  console.log('proxyError: ' + err);
});

proxy.on('end', function(req, res) {
  console.log('proxy sent a response');
});

// proxy server
http.createServer(function(req, res) {
  console.log('proxy received a request');
  proxy.proxyRequest(req, res, { host: 'localhost', port: 8001 });
}).listen(8000);

run this node script and execute:

$ curl -v localhost:8000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment