Skip to content

Instantly share code, notes, and snippets.

@aniruddhanath
Created August 12, 2016 05:58
Show Gist options
  • Save aniruddhanath/fab9b64fe4440d06178540e86e9fd1e3 to your computer and use it in GitHub Desktop.
Save aniruddhanath/fab9b64fe4440d06178540e86e9fd1e3 to your computer and use it in GitHub Desktop.
Simple HTTP Proxy Server with Node.js
const http = require('http');
const url = require('url');
http.createServer(onRequest).listen(3000);
function onRequest (req, res) {
console.log('serving: ' + req.url);
const u = url.parse(req.url);
const options = {
hostname: u.hostname,
port: 80,
path: u.path,
method: 'GET'
};
var proxy = http.request(options, function (proxy_res) {
proxy_res.pipe(res, {
end: true
});
});
req.pipe(proxy, {
end: true
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment