Skip to content

Commit 310f84d

Browse files
committed
fix the start issue when webinterface is disabled, andd add test cases
1 parent 1405356 commit 310f84d

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

proxy.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,16 +329,17 @@ class ProxyServer extends ProxyCore {
329329
// start web interface if neeeded
330330
if (this.proxyWebinterfaceConfig && this.proxyWebinterfaceConfig.enable) {
331331
this.webServerInstance = new WebInterface(this.proxyWebinterfaceConfig, this.recorder);
332-
}
333-
334-
// start web server
335-
this.webServerInstance.start().then(() => {
336-
// start proxy core
332+
// start web server
333+
this.webServerInstance.start().then(() => {
334+
// start proxy core
335+
super.start();
336+
})
337+
.catch((e) => {
338+
this.emit('error', e);
339+
});
340+
} else {
337341
super.start();
338-
})
339-
.catch((e) => {
340-
this.emit('error', e);
341-
});
342+
}
342343
}
343344

344345
close() {

test/spec_rule/no_rule_spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ const ProxyServerUtil = require('../util/ProxyServerUtil.js');
3131

3232
testRequest('http');
3333
testRequest('https');
34+
testRequest('http', false);
35+
testRequest('https', false);
3436

3537
// Test suites for http and https request
36-
function testRequest(protocol = 'http') {
38+
function testRequest(protocol = 'http', needWeb = true) {
3739
function constructUrl(urlPath) {
3840
return generateUrl(protocol, urlPath);
3941
}
@@ -47,7 +49,7 @@ function testRequest(protocol = 'http') {
4749
printLog('Start server for no_rule_spec');
4850

4951
serverInstance = new Server();
50-
proxyServer = ProxyServerUtil.defaultProxyServer();
52+
proxyServer = ProxyServerUtil.defaultProxyServer(needWeb);
5153
setTimeout(() => {
5254
done();
5355
}, 2000);

test/util/ProxyServerUtil.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ const DEFAULT_OPTIONS = {
2323
*
2424
* @return An instance of proxy, could be closed by calling `instance.close()`
2525
*/
26-
function defaultProxyServer() {
26+
function defaultProxyServer(webinterfaceEnable = true) {
2727
const AnyProxy = util.freshRequire('../proxy.js');
2828

2929
const options = util.merge({}, DEFAULT_OPTIONS);
30+
util.merge(options, {
31+
webInterface: {
32+
enable: webinterfaceEnable,
33+
webPort: 8002
34+
}
35+
})
3036
const instance = new AnyProxy.ProxyServer(options);
3137
instance.on('error', e => {
3238
console.log('server instance error', e);

0 commit comments

Comments
 (0)