anyproxy node proxy.js command fails! No WebPort opened.

piah890a  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(45)

#ISSUE
When I start the proxy using the command"node proxy.js" it does not open the web port (8002) and it seems that it starts and stops

This is the configuration of proxy.js file
//Loads Anyproxy
const AnyProxy = require('anyproxy');
const exec = require('child_process').exec;

if (!AnyProxy.utils.certMgr.ifRootCAFileExists()) {
AnyProxy.utils.certMgr.generateRootCA((error, keyPath) => {
// let users to trust this CA before using proxy
if (!error) {
const certDir = require('path').dirname(keyPath);
console.log('The cert is generated at', certDir);
const isWin = /^win/.test(process.platform);
if (isWin) {
exec('start .', { cwd: certDir });
} else {
exec('open .', { cwd: certDir });
}
} else {
console.error('error when generating rootCA', error);
}
});
}

//AnyProxy options
const options = {
port: 8001,
rule: require('ourRULE'),
webInterface: {
enable: true,
webPort: 8002
},
//throttle-unlimited kb/s
//throttle: 10000,
//ignore certificate error in request
dangerouslyIgnoreUnauthorized: true,
//force intercept all https requests
forceProxyHttps: true,
//intercept websocket
wsIntercept: true,
//console output
silent: false
};

//Start the service with the options
const proxyServer = new AnyProxy.ProxyServer(options);

proxyServer.on('ready', () => { /* */ });
proxyServer.on('error', (e) => { console.error('AnyProxy server error: ', e); });

//Start AnyProxy
console.log('//Starting proxyServer//')
proxyServer.start();
console.log('//////////////////////')
console.log('//proxyServer started//')
console.log('//////////////////////')

//Stop AnyProxy
console.log('//Stoping proxyServer//')
proxyServer.close();
console.log('////////////////////')
console.log('//proxyServer ends///')
console.log('////////////////////')

Which platform are you running AnyProxy

Linux

The version of the AnyProxy

anyproxy@4.0.10

Your expected behavior of AnyProxy
  • Listen on port 8082
  • Start the proxy and don't stop it

If I start the server like with the command "node_modules/anyproxy/bin/anyproxy", "--intercept", "--ws-intercept", "--rule", "node_modules/ourRule.js" it works and the output is
2018-05-18T08:11:43.036257369Z [AnyProxy Log][2018-05-18 08:11:43]: Http proxy started on port 8001
2018-05-18T08:11:43.039176665Z [AnyProxy Log][2018-05-18 08:11:43]: web interface started on port 8002
2018-05-18T08:11:43.039200780Z [AnyProxy Log][2018-05-18 08:11:43]: Active rule is: a rule to intercept requests to ourRULE

The actual behavior of AnyProxy

The proxy starts and ends and it does not open port 8002

The log of the error

//Starting proxyServer//
//////////////////////
//proxyServer started//
//////////////////////
//Stoping proxyServer//
[AnyProxy Log][2018-05-18 08:04:51]: clearing cache file...
[AnyProxy Log][2018-05-18 08:04:51]: closing webserver...
////////////////////
//proxyServer ends///
////////////////////
[AnyProxy Log][2018-05-18 08:04:51]: Http proxy started on port 8001
[AnyProxy Log][2018-05-18 08:04:51]: Active rule is: a rule to intercept requests

wd2eg0qa

wd2eg0qa1#

do you happen to call proxyServer.close() in your custom node script?

相关问题