Skip to content

Instantly share code, notes, and snippets.

@reu reu/proxy.js
Created Mar 22, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.