forked from alibaba/anyproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore_reload.js
More file actions
47 lines (35 loc) · 1.28 KB
/
Copy pathcore_reload.js
File metadata and controls
47 lines (35 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const AnyProxy = require('../proxy');
const exec = require('child_process').exec;
const AnyProxyRecorder = require('../lib/recorder');
const WebInterfaceLite = require('../lib/webInterface');
/*
-------------------------------
| ProxyServerA | ProxyServerB |
------------------------------- ----------------------------
| Common Recorder | -------(by events)------| WebInterfaceLite |
------------------------------- ----------------------------
*/
const commonRecorder = new AnyProxyRecorder();
// web interface依赖recorder
new WebInterfaceLite({ // common web interface
webPort: 8002
}, commonRecorder);
// proxy core只依赖recorder,与webServer无关
const optionsA = {
port: 8001,
recorder: commonRecorder, // use common recorder
};
const optionsB = {
port: 8005,
recorder: commonRecorder, // use common recorder
};
const proxyServerA = new AnyProxy.ProxyCore(optionsA);
const proxyServerB = new AnyProxy.ProxyCore(optionsB);
proxyServerA.start();
proxyServerB.start();
// after both ready
setTimeout(() => {
exec('curl http://www.qq.com --proxy http://127.0.0.1:8001');
exec('curl http://www.sina.com.cn --proxy http://127.0.0.1:8005');
}, 1000);
// visit http://127.0.0.1 , there should be two records