reconstruct map local

This commit is contained in:
OttoMao
2015-07-07 17:31:56 +08:00
parent b595e3aa9c
commit 8a146f7373
36 changed files with 56684 additions and 530 deletions

View File

@@ -1,5 +1,12 @@
var utils = require("./util"),
bodyParser = require("body-parser"),
fs = require("fs");
var isRootCAFileExists = require("./certMgr.js").isRootCAFileExists(),
interceptFlag = false;
interceptFlag = false;
//e.g. [ { keyword: 'aaa', local: '/Users/Stella/061739.pdf' } ]
var mapConfig = [];
module.exports = {
summary:function(){
@@ -15,13 +22,30 @@ module.exports = {
if(req.method == "OPTIONS"){
return true;
}else{
return false;
var simpleUrl = (req.headers.host || "") + (req.url || "");
mapConfig.map(function(item){
var key = item.keyword;
if(simpleUrl.indexOf(key) >= 0){
req.anyproxy_map_local = item.local;
return false;
}
});
return !!req.anyproxy_map_local;
}
},
dealLocalResponse : function(req,reqBody,callback){
if(req.method == "OPTIONS"){
callback(200,mergeCORSHeader(req.headers),"");
}else if(req.anyproxy_map_local){
try{
var fileContent = fs.readFile(req.anyproxy_map_local,function(err,buffer){
callback(200, {}, buffer);
});
}catch(e){
callback(200, {}, "failed to load local file :" + req.anyproxy_map_local);
}
}
},
@@ -61,8 +85,33 @@ module.exports = {
//fetch entire traffic data
fetchTrafficData: function(id,info){},
setInterceptFlag:function(flag){
setInterceptFlag: function(flag){
interceptFlag = flag && isRootCAFileExists;
},
_plugIntoWebinterface: function(app,cb){
app.get("/filetree",function(req,res){
try{
var root = req.query.root || process.env.HOME || "/";
utils.filewalker(root,function(err, info){
res.json(info);
});
}catch(e){
res.end(e);
}
});
app.use(bodyParser.json());
app.get("/getMapConfig",function(req,res){
res.json(mapConfig);
});
app.post("/setMapConfig",function(req,res){
mapConfig = req.body;
res.json(mapConfig);
});
cb();
}
};