Created
April 16, 2020 17:12
-
-
Save stefanocudini/79e4c87f5509c4a08dc65ea8c26f4d95 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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