allow user to close the web interface

This commit is contained in:
OttoMao 2014-11-04 17:23:52 +08:00
parent 93aa79b02a
commit ccb6b817de
4 changed files with 55 additions and 45 deletions

View File

@ -242,6 +242,7 @@ var options = {
socketPort : 8003, // optional, internal port for web socket, replace this when it is conflict with your own service socketPort : 8003, // optional, internal port for web socket, replace this when it is conflict with your own service
webConfigPort : 8088, // optional, internal port for web config(beta), replace this when it is conflict with your own service webConfigPort : 8088, // optional, internal port for web config(beta), replace this when it is conflict with your own service
throttle : 10, // optional, speed limit in kb/s throttle : 10, // optional, speed limit in kb/s
disableWebInterface : false //option, set it when you don't want to use the web interface
}; };
new proxy.proxyServer(options); new proxy.proxyServer(options);

3
bin.js
View File

@ -48,7 +48,8 @@ if(program.clear){
hostname : program.hostname, hostname : program.hostname,
dbFile : program.file, dbFile : program.file,
throttle : program.throttle, throttle : program.throttle,
rule : ruleModule rule : ruleModule,
disableWebInterface:false
}); });
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "anyproxy", "name": "anyproxy",
"version": "2.7.3", "version": "2.7.4",
"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": {

View File

@ -65,18 +65,20 @@ if(fs.existsSync(process.cwd() + '/rule.js')){
//option.webConfigPort : 8088(default) //option.webConfigPort : 8088(default)
//option.dbFile : null(default) //option.dbFile : null(default)
//option.throttle : null(default) //option.throttle : null(default)
//option.disableWebInterface
function proxyServer(option){ function proxyServer(option){
option = option || {}; option = option || {};
var self = this, var self = this,
proxyType = /https/i.test(option.type || DEFAULT_TYPE) ? T_TYPE_HTTPS : T_TYPE_HTTP , proxyType = /https/i.test(option.type || DEFAULT_TYPE) ? T_TYPE_HTTPS : T_TYPE_HTTP ,
proxyPort = option.port || DEFAULT_PORT, proxyPort = option.port || DEFAULT_PORT,
proxyHost = option.hostname || DEFAULT_HOST, proxyHost = option.hostname || DEFAULT_HOST,
proxyRules = option.rule || default_rule, proxyRules = option.rule || default_rule,
proxyWebPort = option.webPort || DEFAULT_WEB_PORT, //port for web interface proxyWebPort = option.webPort || DEFAULT_WEB_PORT, //port for web interface
socketPort = option.socketPort || DEFAULT_WEBSOCKET_PORT, //port for websocket socketPort = option.socketPort || DEFAULT_WEBSOCKET_PORT, //port for websocket
proxyConfigPort = option.webConfigPort || DEFAULT_CONFIG_PORT; //port to ui config server proxyConfigPort = option.webConfigPort || DEFAULT_CONFIG_PORT, //port to ui config server
disableWebInterface = !!option.disableWebInterface ;
if(option.dbFile){ if(option.dbFile){
GLOBAL.recorder = new Recorder({filename: option.dbFile}); GLOBAL.recorder = new Recorder({filename: option.dbFile});
}else{ }else{
@ -124,45 +126,51 @@ function proxyServer(option){
//start web interface //start web interface
function(callback){ function(callback){
if(disableWebInterface){
//web interface console.log('web interface is disabled');
var args = [proxyWebPort, socketPort, proxyConfigPort, requestHandler.getRuleSummary(), ip.address()]; callback(null);
var child_webServer = fork(path.join(__dirname,"./webServer.js"),args); }else{
child_webServer.on("message",function(data){
if(data.type == "reqBody" && data.id){ //web interface
child_webServer.send({ var args = [proxyWebPort, socketPort, proxyConfigPort, requestHandler.getRuleSummary(), ip.address()];
type : "body", var child_webServer = fork(path.join(__dirname,"./webServer.js"),args);
id : data.id, child_webServer.on("message",function(data){
body : GLOBAL.recorder.getBody(data.id) if(data.type == "reqBody" && data.id){
}); child_webServer.send({
} type : "body",
}); id : data.id,
body : GLOBAL.recorder.getBody(data.id)
//kill web server when father process exits });
process.on("exit",function(){ }
child_webServer.kill();
});
GLOBAL.recorder.on("update",function(data){
child_webServer.send({
type: "update",
body: data
}); });
});
var configServer = new UIConfigServer(proxyConfigPort); //TODO : uncaught exception
configServer.on("rule_changed",function() { //kill web server when father process exits
// console.log(arguments); process.on("exit",function(){
}) child_webServer.kill();
});
var tipText,webUrl; GLOBAL.recorder.on("update",function(data){
webUrl = "http://" + ip.address() + ":" + proxyWebPort +"/"; child_webServer.send({
tipText = "web interface started at : " + webUrl; type: "update",
console.log(color.green(tipText)); body: data
});
});
tipText = "[alpha]qr code to for iOS client: " + webUrl + "qr"; var configServer = new UIConfigServer(proxyConfigPort);
console.log(color.green(tipText)); configServer.on("rule_changed",function() {
callback(null); // console.log(arguments);
});
var tipText,webUrl;
webUrl = "http://" + ip.address() + ":" + proxyWebPort +"/";
tipText = "web interface started at : " + webUrl;
console.log(color.green(tipText));
tipText = "[alpha]qr code to for iOS client: " + webUrl + "qr";
console.log(color.green(tipText));
callback(null);
}
} }
], ],