Last active
September 16, 2020 18:29
-
-
Save nikitaeverywhere/c0d0ea80c0de4d018121c80c5d2c3653 to your computer and use it in GitHub Desktop.
This file contains 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
// Load testing of http-proxy node library. | |
// $ docker run -it --rm bash:4.4 | |
// $ docker run -it --rm node:12-alpine sh | |
// # mkdir -p /test && cd /test && wget https://github.com/tsenart/vegeta/releases/download/v12.8.3/vegeta-12.8.3-linux-amd64.tar.gz && tar -xvf vegeta-12.8.3-linux-amd64.tar.gz | |
// # wget -O - https://gist.githubusercontent.com/ZitRos/c0d0ea80c0de4d018121c80c5d2c3653/raw/node-http-proxy-load-test.js > index.js && npm install http-proxy | |
// # node index.js & sleep 0.5 && echo 'GET http://localhost/favicon.ico' | ./vegeta attack -rate 15 -duration 5s | ./vegeta report -every 1s && pkill node | |
const http = require('http'); | |
const httpProxy = require('http-proxy'); | |
const port = 80; | |
var proxy = httpProxy.createProxyServer({}); | |
proxy.on('error', (err, req, res) => { | |
console.log('ERROR', err); | |
res.writeHead(502, {}); | |
res.end(''); | |
}); | |
proxy.on('open', function (proxySocket) { | |
// | |
}); | |
proxy.on('proxyReq', function(proxyReq, req, res, options) { | |
// | |
}); | |
var server = http.createServer(function(req, res) { | |
proxy.web(req, res, { | |
target: 'https://www.google.com', | |
changeOrigin: true | |
}); | |
}); | |
console.log("listening on port " + port); | |
server.listen(port); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment