-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathweinre.js
77 lines (63 loc) · 1.82 KB
/
weinre.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
var ui = require('./ui.js')
var url = require('url')
var markup = require('./markup.js')
var weinre = require('weinre')
module.exports = {
proxy: weinreInjector
}
var port = 49369
var weinreRunning = false
ui.tabs.push({
label: 'weinres',
link: '/weinres'
})
function startWeinreForm(req, res) {
res.setHeader('content-type', 'text/html;charset=utf-8')
res.write('<form method="post" action="/weinres">')
res.write(' <button type="submit">')
res.write(' Start weinre server on 0.0.0.0:' + port + ' (access it on weinre.local, cause magicproxy will proxy it.)')
res.write(' </button>')
res.write('</form>')
res.end()
}
ui.router.get('/weinres', function (req, res) {
if (!weinreRunning) {
startWeinreForm(req, res)
} else {
res.writeHead(302, { location: 'http://weinre.local/' })
res.end()
//res.end('<iframe src="http://weinre.local/"></iframe>');
}
})
ui.router.post('/weinres', function (req, res) {
weinre.run({
boundHost: '-all-',
httpPort: port,
verbose: true,
debug: true,
readTimeout: 120,
deathTimeout: 120
})
weinreRunning = true
res.writeHead(302, { location: 'http://weinre.local/' })
res.end()
})
function weinreInjector(req, res, plugin) {
var remoteUrl = url.parse(req.url)
if (remoteUrl.host === 'weinre.local') {
req.url = req.url.replace(/weinre.local/, 'localhost:' + port)
return false;
}
if (!weinreRunning) {
return false;
}
return; // TODO
markup.markup(req, res, [
{
insert: {
after: 'title', // TODO append to <head> instead
markup: '<script src="http://weinre.local/target/target-script-min.js#anonymous"></script>'
}
}
])
}