Skip to content

Instantly share code, notes, and snippets.

@andrewwakeling
Created December 4, 2018 23:14
Show Gist options
  • Save andrewwakeling/c6c63914482bea2e84c0b0988bb2308c to your computer and use it in GitHub Desktop.
Save andrewwakeling/c6c63914482bea2e84c0b0988bb2308c to your computer and use it in GitHub Desktop.
Simple code to proxy localhost to a particular host
const http = require('http');
function onRequest(clientReq, clientRes) {
console.log(`serve: ${clientReq.url}`);
const options = {
hostname: 'foo.ngrok.io',
port: 80,
path: clientReq.url,
method: 'GET',
};
const proxy = http.request(options, (res) => {
res.pipe(
clientRes,
{
end: true,
},
);
});
clientReq.pipe(
proxy,
{
end: true,
},
);
}
http.createServer(onRequest).listen(3001);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment