This repository has been archived by the owner on Oct 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathindex.js
79 lines (64 loc) · 1.88 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
'use strict';
var p = require('path')
var http = require('http')
var https = require('https')
var Promise = require('bluebird')
var interactor = require('./lib/job/interactor.js')
var fs = Promise.promisifyAll(require('fs'))
var config = require('./lib/config.js')()
var https_options = {
key: fs.readFileSync(config.https.key),
cert: fs.readFileSync(config.https.cert)
}
require('./server.js')(config)
.then(function(app) {
var server = http.createServer(app)
.listen(config.port, function() {
if(!config.quiet)
console.log('HTTP listening on %s', config.port)
})
var socket = require('./lib/socket.js')(server, app)
if(config.https.enabled) {
var httpsServer = https.createServer(https_options, app)
.listen(config.https.port, function() {
if(!config.quiet)
console.log('HTTPS listening on %s', config.https.port)
})
var httpssocket = require('./lib/socket.js')(server, app)
}
var plugins = app.get('plugins')
var plugins_paths = []
for(let i in plugins) {
if('job' in plugins[i]) {
plugins_paths.push(plugins[i].path)
}
}
if(interactor.job) {
console.error('Interactor already launched')
return Promise.resolve()
}
interactor.on('error', function(err) {
console.error('Interactor errored');
console.error(err);
})
var cache = app.get('cache')
return interactor.run(plugins_paths, config, cache)
.then(function() {
interactor.ipc.on('notify:*', function(data) {
var event = this.event
setTimeout(function() {
let num = data.length
let d = data.pop()
d.num = num
socket.publish('/'+event.replace(':', '/'), d)
if(httpssocket) {
httpssocket.publish('/'+event.replace(':', '/'), d)
}
}, 1000)
})
})
})
.catch(function(err) {
console.error('Error while initializing explorer')
console.error(err.stack)
})