mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-24 08:41:31 +00:00
Merge pull request #329 from alibaba/webinterfac-fix
fix the start issue when webinterface is disabled, andd add test cases
This commit is contained in:
commit
a5027340dc
5
proxy.js
5
proxy.js
@ -329,8 +329,6 @@ class ProxyServer extends ProxyCore {
|
||||
// start web interface if neeeded
|
||||
if (this.proxyWebinterfaceConfig && this.proxyWebinterfaceConfig.enable) {
|
||||
this.webServerInstance = new WebInterface(this.proxyWebinterfaceConfig, this.recorder);
|
||||
}
|
||||
|
||||
// start web server
|
||||
this.webServerInstance.start().then(() => {
|
||||
// start proxy core
|
||||
@ -339,6 +337,9 @@ class ProxyServer extends ProxyCore {
|
||||
.catch((e) => {
|
||||
this.emit('error', e);
|
||||
});
|
||||
} else {
|
||||
super.start();
|
||||
}
|
||||
}
|
||||
|
||||
close() {
|
||||
|
@ -31,9 +31,11 @@ const ProxyServerUtil = require('../util/ProxyServerUtil.js');
|
||||
|
||||
testRequest('http');
|
||||
testRequest('https');
|
||||
testRequest('http', false);
|
||||
testRequest('https', false);
|
||||
|
||||
// Test suites for http and https request
|
||||
function testRequest(protocol = 'http') {
|
||||
function testRequest(protocol = 'http', needWeb = true) {
|
||||
function constructUrl(urlPath) {
|
||||
return generateUrl(protocol, urlPath);
|
||||
}
|
||||
@ -47,7 +49,7 @@ function testRequest(protocol = 'http') {
|
||||
printLog('Start server for no_rule_spec');
|
||||
|
||||
serverInstance = new Server();
|
||||
proxyServer = ProxyServerUtil.defaultProxyServer();
|
||||
proxyServer = ProxyServerUtil.defaultProxyServer(needWeb);
|
||||
setTimeout(() => {
|
||||
done();
|
||||
}, 2000);
|
||||
|
@ -23,10 +23,16 @@ const DEFAULT_OPTIONS = {
|
||||
*
|
||||
* @return An instance of proxy, could be closed by calling `instance.close()`
|
||||
*/
|
||||
function defaultProxyServer() {
|
||||
function defaultProxyServer(webinterfaceEnable = true) {
|
||||
const AnyProxy = util.freshRequire('../proxy.js');
|
||||
|
||||
const options = util.merge({}, DEFAULT_OPTIONS);
|
||||
util.merge(options, {
|
||||
webInterface: {
|
||||
enable: webinterfaceEnable,
|
||||
webPort: 8002
|
||||
}
|
||||
})
|
||||
const instance = new AnyProxy.ProxyServer(options);
|
||||
instance.on('error', e => {
|
||||
console.log('server instance error', e);
|
||||
|
Loading…
x
Reference in New Issue
Block a user