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,6 +65,7 @@ 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 || {};
@ -75,7 +76,8 @@ function proxyServer(option){
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});
@ -124,6 +126,10 @@ function proxyServer(option){
//start web interface //start web interface
function(callback){ function(callback){
if(disableWebInterface){
console.log('web interface is disabled');
callback(null);
}else{
//web interface //web interface
var args = [proxyWebPort, socketPort, proxyConfigPort, requestHandler.getRuleSummary(), ip.address()]; var args = [proxyWebPort, socketPort, proxyConfigPort, requestHandler.getRuleSummary(), ip.address()];
@ -138,6 +144,7 @@ function proxyServer(option){
} }
}); });
//TODO : uncaught exception
//kill web server when father process exits //kill web server when father process exits
process.on("exit",function(){ process.on("exit",function(){
child_webServer.kill(); child_webServer.kill();
@ -153,7 +160,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); // console.log(arguments);
}) });
var tipText,webUrl; var tipText,webUrl;
webUrl = "http://" + ip.address() + ":" + proxyWebPort +"/"; webUrl = "http://" + ip.address() + ":" + proxyWebPort +"/";
@ -164,6 +171,7 @@ function proxyServer(option){
console.log(color.green(tipText)); console.log(color.green(tipText));
callback(null); callback(null);
} }
}
], ],
//final callback //final callback