1.add watchdog for web server 2.remove optional dep

This commit is contained in:
加里 2014-12-10 14:49:20 +08:00
parent 1e3beaf582
commit 916d458aa2
3 changed files with 25 additions and 42 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "anyproxy", "name": "anyproxy",
"version": "2.9.3", "version": "3.0.0",
"description": "A fully configurable proxy in NodeJS, which can handle HTTPS requests perfectly.", "description": "A fully configurable proxy in NodeJS, which can handle HTTPS requests perfectly.",
"main": "proxy.js", "main": "proxy.js",
"bin": { "bin": {
@ -13,6 +13,7 @@
"commander": "~2.3.0", "commander": "~2.3.0",
"entities": "^1.1.1", "entities": "^1.1.1",
"express": "^4.8.5", "express": "^4.8.5",
"ip": "^0.3.2",
"juicer": "^0.6.6-stable", "juicer": "^0.6.6-stable",
"nedb": "^0.11.0", "nedb": "^0.11.0",
"qrcode-npm": "0.0.3", "qrcode-npm": "0.0.3",
@ -20,27 +21,12 @@
"ws": "^0.4.32" "ws": "^0.4.32"
}, },
"devDependencies": { "devDependencies": {
"proxy-eval": "^1.1.0" "proxy-eval": ">=1.1.1"
}, },
"scripts": { "scripts": {
"test": "node test.js" "test": "node test.js"
}, },
"optionalDependencies": { "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"
},
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/alibaba/anyproxy" "url": "https://github.com/alibaba/anyproxy"

View File

@ -1,22 +1,5 @@
//mix some modules to global.util
try{ try{
GLOBAL.util = require('./lib/util'); 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');
}catch(e){} }catch(e){}
var http = require('http'), 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 //kill web server when father process exits
process.on("exit",function(code){ process.on("exit",function(code){
child_webServer.kill(); child_webServer.kill();
@ -168,7 +158,6 @@ function proxyServer(option){
process.exit(); process.exit();
}); });
GLOBAL.recorder.on("update",function(data){ GLOBAL.recorder.on("update",function(data){
child_webServer.send({ child_webServer.send({
type: "update", type: "update",
@ -177,9 +166,7 @@ function proxyServer(option){
}); });
var configServer = new UIConfigServer(proxyConfigPort); var configServer = new UIConfigServer(proxyConfigPort);
configServer.on("rule_changed",function() { configServer.on("rule_changed",function() {});
// console.log(arguments);
});
var tipText,webUrl; var tipText,webUrl;
webUrl = "http://" + ip.address() + ":" + proxyWebPort +"/"; webUrl = "http://" + ip.address() + ":" + proxyWebPort +"/";

View File

@ -116,7 +116,8 @@ inherits(proxyWebServer, events.EventEmitter);
var param = process.argv.slice(2), var param = process.argv.slice(2),
server = new proxyWebServer(param[0],param[1],param[2],param[3],param[4]), 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){ process.on("message",function(data){
@ -130,9 +131,18 @@ process.on("message",function(data){
cbMap[key].body = data.body; cbMap[key].body = data.body;
cbMap[key].cb.call(null,data.body); cbMap[key].cb.call(null,data.body);
}catch(e){} }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){ function fetchBody(id,cb){
var key = id + ""; var key = id + "";
if(cbMap[key]){ if(cbMap[key]){