Skip to content

Instantly share code, notes, and snippets.

@creativearmenia
Last active September 1, 2020 10:43
Show Gist options
  • Save creativearmenia/66593d5a2b8b3f6d3baef67364fa2de8 to your computer and use it in GitHub Desktop.
Save creativearmenia/66593d5a2b8b3f6d3baef67364fa2de8 to your computer and use it in GitHub Desktop.
Simple proxy
const http = require('http');
const httpProxy = require('http-proxy');
const url = require('url');
let proxy = httpProxy.createProxyServer();
let server = http.createServer(function(req, res)
{
const queryObject = url.parse(req.url, true).query;
if(queryObject["target"])
{
proxy.web(req, res,
{
target: queryObject["target"],
changeOrigin: true,
ignorePath:true
}
);
}
else
{
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({ }));
}
});
server.listen(8000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment