mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-23 20:31:25 +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
19
proxy.js
19
proxy.js
@ -329,16 +329,17 @@ class ProxyServer extends ProxyCore {
|
|||||||
// start web interface if neeeded
|
// start web interface if neeeded
|
||||||
if (this.proxyWebinterfaceConfig && this.proxyWebinterfaceConfig.enable) {
|
if (this.proxyWebinterfaceConfig && this.proxyWebinterfaceConfig.enable) {
|
||||||
this.webServerInstance = new WebInterface(this.proxyWebinterfaceConfig, this.recorder);
|
this.webServerInstance = new WebInterface(this.proxyWebinterfaceConfig, this.recorder);
|
||||||
}
|
// start web server
|
||||||
|
this.webServerInstance.start().then(() => {
|
||||||
// start web server
|
// start proxy core
|
||||||
this.webServerInstance.start().then(() => {
|
super.start();
|
||||||
// start proxy core
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
this.emit('error', e);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
super.start();
|
super.start();
|
||||||
})
|
}
|
||||||
.catch((e) => {
|
|
||||||
this.emit('error', e);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
|
@ -31,9 +31,11 @@ const ProxyServerUtil = require('../util/ProxyServerUtil.js');
|
|||||||
|
|
||||||
testRequest('http');
|
testRequest('http');
|
||||||
testRequest('https');
|
testRequest('https');
|
||||||
|
testRequest('http', false);
|
||||||
|
testRequest('https', false);
|
||||||
|
|
||||||
// Test suites for http and https request
|
// Test suites for http and https request
|
||||||
function testRequest(protocol = 'http') {
|
function testRequest(protocol = 'http', needWeb = true) {
|
||||||
function constructUrl(urlPath) {
|
function constructUrl(urlPath) {
|
||||||
return generateUrl(protocol, urlPath);
|
return generateUrl(protocol, urlPath);
|
||||||
}
|
}
|
||||||
@ -47,7 +49,7 @@ function testRequest(protocol = 'http') {
|
|||||||
printLog('Start server for no_rule_spec');
|
printLog('Start server for no_rule_spec');
|
||||||
|
|
||||||
serverInstance = new Server();
|
serverInstance = new Server();
|
||||||
proxyServer = ProxyServerUtil.defaultProxyServer();
|
proxyServer = ProxyServerUtil.defaultProxyServer(needWeb);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
done();
|
done();
|
||||||
}, 2000);
|
}, 2000);
|
||||||
|
@ -23,10 +23,16 @@ const DEFAULT_OPTIONS = {
|
|||||||
*
|
*
|
||||||
* @return An instance of proxy, could be closed by calling `instance.close()`
|
* @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 AnyProxy = util.freshRequire('../proxy.js');
|
||||||
|
|
||||||
const options = util.merge({}, DEFAULT_OPTIONS);
|
const options = util.merge({}, DEFAULT_OPTIONS);
|
||||||
|
util.merge(options, {
|
||||||
|
webInterface: {
|
||||||
|
enable: webinterfaceEnable,
|
||||||
|
webPort: 8002
|
||||||
|
}
|
||||||
|
})
|
||||||
const instance = new AnyProxy.ProxyServer(options);
|
const instance = new AnyProxy.ProxyServer(options);
|
||||||
instance.on('error', e => {
|
instance.on('error', e => {
|
||||||
console.log('server instance error', e);
|
console.log('server instance error', e);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user