-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
87 lines (80 loc) · 2.04 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const ffp = require('find-free-port');
const os = require('os');
const weinre = require('./weinre/lib/weinre');
const utils = require('./weinre/lib/utils');
function getExternalIp() {
const ifaces = os.networkInterfaces();
const ips = [];
Object.keys(ifaces).forEach((dev) => {
ifaces[dev].forEach((details) => {
if (details.family === 'IPv4' && details.address !== '127.0.0.1') {
ips.push(details.address);
}
});
});
return ips.length > 0 ? ips[0] : 'localhost';
}
module.exports = {
configSchema: {
httpPort: {
type: 'number',
},
boundHost: {
type: 'string',
default: getExternalIp(),
},
verbose: {
type: 'boolean',
default: false,
},
debug: {
type: 'boolean',
default: false,
},
readTimeout: {
type: 'number',
default: 5,
},
deathTimeout: {
type: 'number',
default: 15,
},
},
assets: {
script: (config) => {
const boundHost = config.get('boundHost');
const httpPort = config.get('httpPort');
return `
(function () {
var script = document.createElement('script');
script.src = 'http://${boundHost}:${httpPort}/target/target-script-min.js#anonymous';
document.body.appendChild(script);
})();
`;
},
},
hooks: {
async onCreate({ config, logger, events }) {
utils.log = (message) => {
logger.debug(message);
};
utils.notify = (message) => {
logger.notify(message);
};
events.on('ready', async () => {
const [vaildPort] = await ffp(config.get('$.port'));
const httpPort = config.get('httpPort') || vaildPort;
config.set('httpPort', httpPort);
const opts = {
httpPort,
boundHost: config.get('boundHost'),
verbose: config.get('verbose'),
debug: config.get('debug'),
readTimeout: config.get('readTimeout'),
deathTimeout: config.get('deathTimeout'),
};
weinre.run(opts);
});
},
},
};