-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
64 lines (54 loc) · 1.44 KB
/
index.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict';
const AnyProxy = require('anyproxy');
const exec = require('child_process').exec;
const ip = require('ip');
const config = require('./config');
const utils = require('./utils');
const logger = require('./utils/logger');
const {
anyproxy: anyproxyConfig,
serverPort,
} = config;
// 引导安装 HTTPS 证书
if (!AnyProxy.utils.certMgr.ifRootCAFileExists()) {
AnyProxy.utils.certMgr.generateRootCA((error, keyPath) => {
if (!error) {
const certDir = require('path').dirname(keyPath);
logger.info('The cert is generated at %s', certDir);
const isWin = /^win/.test(process.platform);
if (isWin) {
exec('start .', { cwd: certDir });
} else {
exec('open .', { cwd: certDir });
}
} else {
logger.error(error);
}
});
}
const ipAddress = ip.address();
const proxyServer = new AnyProxy.ProxyServer({
...anyproxyConfig,
// 所有的抓取规则
rule: require('./rule'),
});
proxyServer.on('ready', () => {
logger.info('请配置HTTP代理: %s:8001', ipAddress);
});
proxyServer.on('error', (e) => {
logger.error(e);
});
// 删除 redis 中对应缓存后再启动
utils.delCrawlLinkCache().then(() => {
proxyServer.start();
}, e => {
logger.error(e);
});
// when finished
// proxyServer.close();
//<<<<<<< HEAD
//require('./server').listen(8004);
//=======
require('./server').listen(serverPort, () => {
logger.info('数据管理页面: http://%s:8004', ipAddress);
});