-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
128 lines (111 loc) · 3.31 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Breach: [mod_strip_advanced] index.js
*
* Based on : mod_strip - Copyright (c) 2014, Stanislas Polu. All rights reserved.
*
* @author: [mod_strip] spolu
* @author: [mod_strip_advanced] air-global
*
* @log:
* - 2014-07-18 air-global rebrand to mod_strip_advanced
* - 2014-06-04 spolu Move to `mod_layout`
* - 2014-01-17 spolu Creation
*/
"use strict"
var express = require('express');
var http = require('http');
var common = require('./lib/common.js');
var breach = require('breach_module');
var async = require('async');
var request = require('request');
/******************************************************************************/
/* MODULE BOOTSTRAP */
/******************************************************************************/
var bootstrap = function(http_srv) {
var http_port = http_srv.address().port;
common._ = {
box: require('./lib/box.js').box({
http_port: http_port
}),
tabs: require('./lib/tabs.js').tabs({}),
strip: require('./lib/strip.js').strip({
http_port: http_port
}),
/*
stack: require('./lib/stack.js').stack({
http_port: http_port
}),
*/
devtools: require('./lib/devtools.js').devtools({
http_port: http_port
})
};
breach.init(function() {
breach.register('.*', 'devtools');
breach.register('mod_strip_advanced', 'box_.*');
breach.register('core', 'tabs:.*');
breach.register('core', 'controls:keyboard');
breach.register('core', 'auto_update:.*');
breach.register('core', 'modules:.*');
breach.expose('init', function(src, args, cb_) {
async.parallel([
common._.box.init,
common._.tabs.init,
common._.strip.init,
//common._.stack.init,
common._.devtools.init
], cb_);
});
breach.expose('kill', function(args, cb_) {
async.parallel([
common._.box.kill,
common._.tabs.kill,
common._.strip.kill,
//common._.stack.kill,
common._.devtools.kill
], function(err) {
common.exit(0);
});
});
});
var io = require('socket.io').listen(http_srv, {
'log level': 1
});
io.sockets.on('connection', function (socket) {
socket.on('handshake', function (name) {
var name_r = /^_(.*)$/;
var name_m = name_r.exec(name);
if(name_m && common._[name_m[1]]) {
common._[name_m[1]].handshake(socket);
}
});
});
};
/******************************************************************************/
/* SETUP */
/******************************************************************************/
(function setup() {
var app = express();
var args = process.argv;
args.forEach(function(a) {
if(a === '--debug') {
common.DEBUG = true;
}
});
/* App Configuration */
app.use('/', express.static(__dirname + '/controls'));
app.use(require('body-parser')());
app.use(require('method-override')())
app.get('/proxy', function(req, res, next) {
request(req.param('url')).pipe(res);
});
var http_srv = http.createServer(app).listen(0, '127.0.0.1');
http_srv.on('listening', function() {
var port = http_srv.address().port;
common.log.out('HTTP Server started on `http://127.0.0.1:' + port + '`');
return bootstrap(http_srv);
});
})();
process.on('uncaughtException', function (err) {
common.fatal(err);
});