clean up some code

This commit is contained in:
OttoMao 2015-07-22 13:26:22 +08:00
parent 4c5bc97542
commit c5a1086c7c
3 changed files with 18 additions and 18 deletions

15
bin.js
View File

@ -6,6 +6,7 @@ var program = require('commander'),
path = require("path"), path = require("path"),
npm = require("npm"), npm = require("npm"),
packageInfo = require("./package.json"), packageInfo = require("./package.json"),
util = require("./lib/util"),
logUtil = require("./lib/log"); logUtil = require("./lib/log");
program program
@ -65,6 +66,20 @@ if(program.clear){
}catch(e){ }catch(e){
logUtil.printLog("failed to load rule file :" + e.toString(), logUtil.T_ERR); logUtil.printLog("failed to load rule file :" + e.toString(), logUtil.T_ERR);
} }
}else{
//a feature for donghua.yan
//read rule file from a specific position
(function(){
try{
var anyproxyHome = path.join(util.getUserHome(),"/.anyproxy/");
if(fs.existsSync(path.join(anyproxyHome,"rule_default.js"))){
ruleModule = require(path.join(anyproxyHome,"rule_default"));
}
if(fs.existsSync(path.join(process.cwd(),'rule.js'))){
ruleModule = require(path.join(process.cwd(),'rule'));
}
}catch(e){}
})();
} }
new proxy.proxyServer({ new proxy.proxyServer({

View File

@ -27,7 +27,6 @@ var http = require('http'),
iconv = require('iconv-lite'), iconv = require('iconv-lite'),
Buffer = require('buffer').Buffer; Buffer = require('buffer').Buffer;
var T_TYPE_HTTP = 0, var T_TYPE_HTTP = 0,
T_TYPE_HTTPS = 1, T_TYPE_HTTPS = 1,
DEFAULT_PORT = 8001, DEFAULT_PORT = 8001,
@ -39,20 +38,6 @@ var T_TYPE_HTTP = 0,
var default_rule = require('./lib/rule_default'); var default_rule = require('./lib/rule_default');
//may be unreliable in windows
try{
var anyproxyHome = path.join(util.getUserHome(),"/.anyproxy/");
if(!fs.existsSync(anyproxyHome)){
fs.mkdirSync(anyproxyHome);
}
if(fs.existsSync(path.join(anyproxyHome,"rule_default.js"))){
default_rule = require(path.join(anyproxyHome,"rule_default"));
}
if(fs.existsSync(path.join(process.cwd(),'rule.js'))){
default_rule = require(path.join(process.cwd(),'rule'));
}
}catch(e){}
//option //option
//option.type : 'http'(default) or 'https' //option.type : 'http'(default) or 'https'
//option.port : 8001(default) //option.port : 8001(default)
@ -169,7 +154,6 @@ function proxyServer(option){
//server status manager //server status manager
function(callback){ function(callback){
//kill web server when father process exits
process.on("exit",function(code){ process.on("exit",function(code){
logUtil.printLog('AnyProxy is about to exit with code: ' + code, logUtil.T_ERR); logUtil.printLog('AnyProxy is about to exit with code: ' + code, logUtil.T_ERR);
process.exit(); process.exit();
@ -211,3 +195,4 @@ function proxyServer(option){
module.exports.proxyServer = proxyServer; module.exports.proxyServer = proxyServer;
module.exports.generateRootCA = certMgr.generateRootCA; module.exports.generateRootCA = certMgr.generateRootCA;
module.exports.isRootCAFileExists = certMgr.isRootCAFileExists; module.exports.isRootCAFileExists = certMgr.isRootCAFileExists;
module.exports.setRules = requestHandler.setRules;

View File

@ -40,8 +40,8 @@ function util_merge(left,right){
onOpen : function(){ onOpen : function(){
eventCenter.dispatchEvent("wsOpen"); eventCenter.dispatchEvent("wsOpen");
}, },
onGetUpdate : function(content){ onGetUpdate : function(record){
eventCenter.dispatchEvent("wsGetUpdate",content); eventCenter.dispatchEvent("wsGetUpdate",record);
}, },
onError : function(e){ onError : function(e){
eventCenter.dispatchEvent("wsEnd"); eventCenter.dispatchEvent("wsEnd");