diff --git a/package.json b/package.json index 07728d8..cdf1c65 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "anyproxy", - "version": "2.9.3", + "version": "3.0.0", "description": "A fully configurable proxy in NodeJS, which can handle HTTPS requests perfectly.", "main": "proxy.js", "bin": { @@ -13,6 +13,7 @@ "commander": "~2.3.0", "entities": "^1.1.1", "express": "^4.8.5", + "ip": "^0.3.2", "juicer": "^0.6.6-stable", "nedb": "^0.11.0", "qrcode-npm": "0.0.3", @@ -20,27 +21,12 @@ "ws": "^0.4.32" }, "devDependencies": { - "proxy-eval": "^1.1.0" + "proxy-eval": ">=1.1.1" }, "scripts": { "test": "node test.js" }, - "optionalDependencies": { - "underscore": "^1.7.0", - "cookie": "^0.1.2", - "mysql": "^2.5.2", - "iconv-lite": "^0.4.4", - "ip": "^0.3.2", - "jquery": "^2.1.1", - "jsdom": "^1.0.3", - "socks5-http-client": "^0.1.6", - "socks5-https-client": "^0.2.2", - "http-proxy-agent":"^0.2.6", - "https-proxy-agent":"^0.3.5", - "tcp-ping":"^0.1.1", - "request":"^2.48.0", - "moment":"^2.8.3" - }, + "optionalDependencies": {}, "repository": { "type": "git", "url": "https://github.com/alibaba/anyproxy" diff --git a/proxy.js b/proxy.js index 27a005c..f2e52f6 100644 --- a/proxy.js +++ b/proxy.js @@ -1,22 +1,5 @@ -//mix some modules to global.util try{ - GLOBAL.util = require('./lib/util'); - GLOBAL.util['iconv-lite'] = require("iconv-lite"); - GLOBAL.util['colorful'] = require("colorful"); - GLOBAL.util['path'] = require("path"); - GLOBAL.util['jsdom'] = require('jsdom'); - GLOBAL.util['cookie'] = require('cookie'); - GLOBAL.util['jquery'] = require('jquery'); - GLOBAL.util['mysql'] = require('mysql'); - GLOBAL.util['Socks5ClientHttpAgent'] = require('socks5-http-client/lib/Agent'); - GLOBAL.util['Socks5ClientHttpsAgent'] = require('socks5-https-client/lib/Agent'); - GLOBAL.util['HttpProxyAgent'] = require('http-proxy-agent'); - GLOBAL.util['HttpsProxyAgent'] = require('https-proxy-agent'); - GLOBAL.util['tcp-ping'] = require('tcp-ping'); - GLOBAL.util['request'] = require('request'); - GLOBAL.util['async'] = require('async'); - GLOBAL.util['underscore'] = require('underscore'); - GLOBAL.util['moment'] = require('moment'); + GLOBAL.util = require('./lib/util'); }catch(e){} var http = require('http'), @@ -155,6 +138,13 @@ function proxyServer(option){ } }); + //watch dog + setInterval(function(argument) { + child_webServer.send({ + type:"watch" + }); + },5000); + //kill web server when father process exits process.on("exit",function(code){ child_webServer.kill(); @@ -168,7 +158,6 @@ function proxyServer(option){ process.exit(); }); - GLOBAL.recorder.on("update",function(data){ child_webServer.send({ type: "update", @@ -177,9 +166,7 @@ function proxyServer(option){ }); var configServer = new UIConfigServer(proxyConfigPort); - configServer.on("rule_changed",function() { - // console.log(arguments); - }); + configServer.on("rule_changed",function() {}); var tipText,webUrl; webUrl = "http://" + ip.address() + ":" + proxyWebPort +"/"; diff --git a/webServer.js b/webServer.js index de50889..54fab85 100644 --- a/webServer.js +++ b/webServer.js @@ -116,7 +116,8 @@ inherits(proxyWebServer, events.EventEmitter); var param = process.argv.slice(2), server = new proxyWebServer(param[0],param[1],param[2],param[3],param[4]), - cbMap = {}; // id body cb + cbMap = {}, // id body cb + lastestHeartbeat = new Date().getTime(); process.on("message",function(data){ @@ -130,9 +131,18 @@ process.on("message",function(data){ cbMap[key].body = data.body; cbMap[key].cb.call(null,data.body); }catch(e){} - } + }else if(data.type == "watch"){ + lastestHeartbeat = new Date().getTime(); + } }); +//watch dog +setInterval(function(){ + if(new Date().getTime() - lastestHeartbeat > 10 * 1000){ + process.exit(); + } +},7000); + function fetchBody(id,cb){ var key = id + ""; if(cbMap[key]){