Skip to content

Instantly share code, notes, and snippets.

@stefanocudini
Created April 16, 2020 17:12
Show Gist options
  • Save stefanocudini/79e4c87f5509c4a08dc65ea8c26f4d95 to your computer and use it in GitHub Desktop.
Save stefanocudini/79e4c87f5509c4a08dc65ea8c26f4d95 to your computer and use it in GitHub Desktop.
var http = require('http');
http.createServer(onRequest).listen(3000);
function onRequest(client_req, client_res) {
console.log('serve: ' + client_req.url);
var options = {
hostname: 'www.google.com',
port: 80,
path: client_req.url,
method: client_req.method,
headers: client_req.headers
};
var proxy = http.request(options, function (res) {
client_res.writeHead(res.statusCode, res.headers)
res.pipe(client_res, {
end: true
});
});
client_req.pipe(proxy, {
end: true
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment