-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
96 lines (81 loc) · 2.33 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
/*
* http-teapot: mod_duckduckgo index.js
*
* Copyright (c) 2014, Thomas Potaire. All rights reserved.
*
* @author: http-teapot
*
* @log:
* - 2014-07-19 http-teapot Creation
*/
'use strict';
var breach = require('breach_module')
, common = require("./lib/common.js")
, express = require('express')
, http = require('http')
, async = require('async');
/******************************************************************************/
/* MODULE BOOTSTRAP */
/******************************************************************************/
var bootstrap = function(http_srv) {
var http_port = http_srv.address().port;
common._ = {
dropdown: require('./lib/dropdown.js').dropdown({
http_port: http_port
}),
};
breach.init(function() {
breach.register('core', 'tabs:.*');
breach.register('mod_strip', 'box_input');
breach.expose('init', function(src, args, cb_) {
async.parallel([
common._.dropdown.init,
], cb_);
});
breach.expose('kill', function(args, cb_) {
async.parallel([
common._.dropdown.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.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);
});