-
Notifications
You must be signed in to change notification settings - Fork 2
/
ui.js
54 lines (43 loc) · 1.36 KB
/
ui.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
var fs = require('fs')
var url = require('url')
var express = require('express')
module.exports = {
proxy: uiProxy,
tabs: [
{
label: 'status',
link: '/status',
}
],
router: new express.Router()
}
function uiProxy(req, res, plugin) {
var remoteUrl = url.parse(req.url)
if (remoteUrl.host !== 'magicproxy.local') {
return false;
}
module.exports.router.middleware(req, res, function fakeNext(err, req, res){
res.end('404! ' + (err || ''))
if (err) console.error(err)
})
return true;
}
module.exports.router.get('/', function (req, res) {
res.setHeader('content-type', 'text/html;charset=utf-8')
res.write(fs.readFileSync('ui.html'))
res.write('<nav id="tabs">' +
module.exports.tabs.map(function (tab) {
var ret =
'<a href="' + ('/' + tab.label || tab.link) + '" ' +
'target="iframe"' +
'>' +
tab.label + '</a>';
return ret
}).join('') +
'</nav>')
res.end('<iframe name="iframe" src="/status"></iframe>')
})
module.exports.router.get('/status', function (req, res) {
res.setHeader('content-type', 'text/html;charset=utf-8')
res.end('<img src="http://38.media.tumblr.com/dc2acffbea837dc5277bb1b469aafbb7/tumblr_n7u8czdwFI1qzs5cqo1_500.gif">')
})