Last active
September 1, 2020 10:43
-
-
Save creativearmenia/66593d5a2b8b3f6d3baef67364fa2de8 to your computer and use it in GitHub Desktop.
Simple proxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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