-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
30 lines (24 loc) · 749 Bytes
/
app.js
File metadata and controls
30 lines (24 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var http = require('http'),
httpProxy = require('http-proxy'),
program = require('commander');
program
.option('--delay <msec>', 'delay all requests for [0] msec', Number, 0)
.option('--emulate-error', 'all requests return HTTP 500', Boolean, false);
program.parse(process.argv);
var proxy = new httpProxy.RoutingProxy();
http.createServer(function (req, res) {
var url = require('url').parse(req.url),
buffer = httpProxy.buffer(req);
setTimeout(function() {
if (program.emulateError) {
res.writeHead(500);
res.end();
} else {
proxy.proxyRequest(req, res, {
host: url.hostname,
port: url.port || 80,
buffer: buffer
});
}
}, program.delay);
}).listen(8080);