Skip to content

Instantly share code, notes, and snippets.

@heerdyes
Created August 1, 2023 16:16
Show Gist options
  • Save heerdyes/ec3421518da8456c1100accff3990c93 to your computer and use it in GitHub Desktop.
Save heerdyes/ec3421518da8456c1100accff3990c93 to your computer and use it in GitHub Desktop.
node proxy server
const http = require('http');
const httpProxy = require('http-proxy');
const proxy = httpProxy.createProxyServer({});
const apisrv = '127.0.0.1:8080';
const port = 3000;
console.log(`[proxy] 127.0.0.1:${port} -> ${apisrv}`);
http.createServer(
function(req, res) {
console.log('[rq]', req.method, req.url);
proxy.web(
req,
res,
{
target: `${req.protocol}://${apisrv}`
}
);
}
).listen(port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment