Created
August 1, 2023 16:16
-
-
Save heerdyes/ec3421518da8456c1100accff3990c93 to your computer and use it in GitHub Desktop.
node proxy server
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 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