mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-24 08:41:31 +00:00
clean up some code
This commit is contained in:
parent
4c5bc97542
commit
c5a1086c7c
15
bin.js
15
bin.js
@ -6,6 +6,7 @@ var program = require('commander'),
|
||||
path = require("path"),
|
||||
npm = require("npm"),
|
||||
packageInfo = require("./package.json"),
|
||||
util = require("./lib/util"),
|
||||
logUtil = require("./lib/log");
|
||||
|
||||
program
|
||||
@ -65,6 +66,20 @@ if(program.clear){
|
||||
}catch(e){
|
||||
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({
|
||||
|
17
proxy.js
17
proxy.js
@ -27,7 +27,6 @@ var http = require('http'),
|
||||
iconv = require('iconv-lite'),
|
||||
Buffer = require('buffer').Buffer;
|
||||
|
||||
|
||||
var T_TYPE_HTTP = 0,
|
||||
T_TYPE_HTTPS = 1,
|
||||
DEFAULT_PORT = 8001,
|
||||
@ -39,20 +38,6 @@ var T_TYPE_HTTP = 0,
|
||||
|
||||
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.type : 'http'(default) or 'https'
|
||||
//option.port : 8001(default)
|
||||
@ -169,7 +154,6 @@ function proxyServer(option){
|
||||
//server status manager
|
||||
function(callback){
|
||||
|
||||
//kill web server when father process exits
|
||||
process.on("exit",function(code){
|
||||
logUtil.printLog('AnyProxy is about to exit with code: ' + code, logUtil.T_ERR);
|
||||
process.exit();
|
||||
@ -211,3 +195,4 @@ function proxyServer(option){
|
||||
module.exports.proxyServer = proxyServer;
|
||||
module.exports.generateRootCA = certMgr.generateRootCA;
|
||||
module.exports.isRootCAFileExists = certMgr.isRootCAFileExists;
|
||||
module.exports.setRules = requestHandler.setRules;
|
||||
|
@ -40,8 +40,8 @@ function util_merge(left,right){
|
||||
onOpen : function(){
|
||||
eventCenter.dispatchEvent("wsOpen");
|
||||
},
|
||||
onGetUpdate : function(content){
|
||||
eventCenter.dispatchEvent("wsGetUpdate",content);
|
||||
onGetUpdate : function(record){
|
||||
eventCenter.dispatchEvent("wsGetUpdate",record);
|
||||
},
|
||||
onError : function(e){
|
||||
eventCenter.dispatchEvent("wsEnd");
|
||||
|
Loading…
x
Reference in New Issue
Block a user