|
| 1 | +var httpProxy = require('http-proxy'), connect = require('connect'), http = require('http'), fs = require('fs'), mkdirp = require('mkdirp') |
| 2 | + |
| 3 | +var bhost="www.bbva.com", bport=80, record_dir="www2" |
| 4 | + |
| 5 | +connect.createServer( connect.static(record_dir)).listen(8000); |
| 6 | + |
| 7 | +httpProxy.createServer(function (req, res, proxy) { //WORKING PROXY |
| 8 | + if(req.url.match(/\.css\?*/)){ |
| 9 | + proxy.proxyRequest(req, res, { host: 'localhost', port: 8000 }) |
| 10 | + } else { |
| 11 | + proxy.proxyRequest(req, res, { host: bhost, port: bport }) |
| 12 | + //try to go to localhost:9001/TLBB/tlbb/esp/index.jsp |
| 13 | + } |
| 14 | +}).listen(9001); |
| 15 | + |
| 16 | + |
| 17 | +httpProxy.createServer(function (req, res, proxy) { //RECORDING MODE PROXY |
| 18 | + if(req.url.match(/\.css\?*/)){ |
| 19 | + var options = { host: bhost , port: bport , path: '/'+req.url} |
| 20 | + var request = http.get(options, function(res2){ |
| 21 | + var imagedata = '' |
| 22 | + var dir_array=options.path.split("/") |
| 23 | + var filename=dir_array.pop() |
| 24 | + res2.setEncoding('binary') |
| 25 | + |
| 26 | + res2.on('data', function(chunk){ imagedata += chunk }) |
| 27 | + |
| 28 | + res2.on('end', function(){ |
| 29 | + mkdirp(record_dir+dir_array.join("/"), function(err) { }); |
| 30 | + fs.writeFile(record_dir+options.path, imagedata, 'binary', function(err){ |
| 31 | + if (err){ console.log("error saving file: ", err) } |
| 32 | + console.log('File saved:',filename) |
| 33 | + }) |
| 34 | + }) |
| 35 | + }) |
| 36 | + proxy.proxyRequest(req, res, { host: bhost, port: bport }) |
| 37 | + } else { |
| 38 | + proxy.proxyRequest(req, res, { host: bhost, port: bport}) |
| 39 | + } |
| 40 | +}).listen(9002); |
| 41 | + |
0 commit comments