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