Skip to content

Instantly share code, notes, and snippets.

@reu
Created March 22, 2019 15:01
Show Gist options
  • Save reu/8a61046cf381a193d5b46f2e06fcf440 to your computer and use it in GitHub Desktop.
Save reu/8a61046cf381a193d5b46f2e06fcf440 to your computer and use it in GitHub Desktop.
Simple HTTP proxy
const http = require("http");
const { PORT, PROXY_HOST, PROXY_PORT } = process.env;
http
.createServer((req, res) => {
const proxyRequest = http
.request({
hostname: PROXY_HOST,
port: PROXY_PORT || 80,
path: req.url,
method: req.method,
headers: {
...req.headers,
host: PROXY_HOST,
},
}, proxyRes => {
res.writeHead(proxyRes.statusCode, proxyRes.headers);
proxyRes.pipe(res, { end: true })
});
req.pipe(proxyRequest, { end: true });
})
.listen(PORT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment