Skip to content

Instantly share code, notes, and snippets.

@torgeir
Created March 11, 2011 08:31
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 torgeir/865626 to your computer and use it in GitHub Desktop.
Save torgeir/865626 to your computer and use it in GitHub Desktop.
node.js proxy
// Kjør med noe ala disse
// $ node proxy.js www.google.no 80
// $ node proxy.js www.vg.no 80
// og sjekk localhost:3000
var http = require('http')
, args = process.argv.splice(2, 2);
http.createServer(function (req, res) {
var options = {
host: args[0] || 'www.google.no'
, port: args[1] || 80
, path: req.url || '/'
};
http.get(options, function(r) {
res.writeHead(r.statusCode, r.headers);
r.
on('data', function (data) {
res.write(data);
}).
on('end', function () {
res.end();
});
}).
on('error', function (e) {
console.log('error ' + e);
});
}).
listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment