-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
51 lines (39 loc) · 1.39 KB
/
index.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env node
'use strict';
var fs = require("fs"),
path = require("path"),
proxy = require("anyproxy"),
beautify = require('js-beautify').js_beautify,
program = require('commander'),
info = require("./package.json");
if(process.argv.length <= 2){
console.log("usage : tr <dir>");
process.exit();
}
var userSavePath = path.resolve(process.cwd(), process.argv[process.argv.length - 1]);
var recorderRule = {
summary:function(){
return "";
},
fetchTrafficData: function(id,info){
var customizedData = info,
resBody = info.resBody;
customizedData.reqHeader = info.req.headers;
delete customizedData["req"];
delete customizedData["resBody"];
saveInfo(id,customizedData.url,customizedData,resBody)
}
};
var options = {
rule : recorderRule,
disableWebInterface : true
};
console.log("your records will be saved at :" + userSavePath);
console.log("please assign the following proxy for your browser");
new proxy.proxyServer(options);
function saveInfo(id,url,summary,body){
var infoFile = path.join(userSavePath, id + "_summary_" + summary.host),
bodyFile = path.join(userSavePath, id + "_body_" + summary.host);
fs.writeFileSync(infoFile , beautify(JSON.stringify(summary), { indent_size: 4 }));
fs.writeFileSync(bodyFile , body);
}