Skip to content

Instantly share code, notes, and snippets.

@alanwei43
Created December 29, 2019 01:06
Show Gist options
  • Save alanwei43/fef15b7f6c0f0b2dc7ec568e94bb5465 to your computer and use it in GitHub Desktop.
Save alanwei43/fef15b7f6c0f0b2dc7ec568e94bb5465 to your computer and use it in GitHub Desktop.
Node HTTP pipe
const http = require("http"),
url = require("url");
http.createServer((proxyReq, proxyRes) => {
console.log(proxyReq.url);
const options = url.parse(proxyReq.url);
const svr = http.request(options, svrRes => {
svrRes.pipe(proxyRes, { end: true });
});
proxyReq.pipe(svr, {
end: true
});
}).listen(3003);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment