Created
March 11, 2011 08:31
-
-
Save torgeir/865626 to your computer and use it in GitHub Desktop.
node.js proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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