alibaba / alibaba/anyproxy

node proxy.js command fails! No WebPort opened.

Open
#381 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.9k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

#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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the proxy.js entry point and inspect the lifecycle around proxyServer.start() and proxyServer.close(). Run node proxy.js and verify that the process remains running and the web interface listens on port 8002, matching the working CLI output in the report.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
networking
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.