In a new directory, create app.js like this:
var http = require('http'), httpProxy = require('http-proxy');Install http-proxy (assuming you are using npm):
// initialize parametersvar listenPort = 5001, destinationPort = 5000, delay = 1000;
// router optionsvar options = { router: { '.*': 'localhost:' + destinationPort }};
// create server and listenvar server = httpProxy.createServer(function(req, res, next) { var delayedResponse = function() { next(); }; setTimeout(delayedResponse, delay);}, options);server.listen(listenPort);
npm install http-proxyAnd kick it:
node app.jsMaking hard coded parameters configurable is left as an exercise to the reader. Hint: process.argv gives you access to command line arguments in Node.
Note that this is *not* simulating low bandwidth, just a sleepy server with high latency; once the delay is over, the proxy will respond with all bandwidth available. Thus, this approach isn't generally suitable to simulate a slow network connection.
No comments:
Post a Comment