-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
58 lines (51 loc) · 1.81 KB
/
app.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
#!/usr/bin/env node
'use strict'
/**
* unblinkingBot - Surveillance system assistant
* @author {@link https:/jmg1138 jmg1138}
* @see {@link http://unblinkingbot.com/ unblinkingBot.com}
*/
const datastores = require(`./lib/datastores`)
const frontends = require(`./lib/frontends`)
const funs = require(`./lib/funs`)
const slacks = require(`./lib/slacks`)
const sockets = require(`./lib/sockets`)
/**
* Starts the unblinkingBot application.
* @see {@link https:/socketio/socket.io socket.io}
* "Starting with 3.0, express applications have become request handler
* functions that you pass to http or http Server instances. You need to pass
* the Server to socket.io, and not the express application function. Also make
* sure to call .listen on the server, not the app."
*/
async function main () {
try {
let db = await datastores.instance()
let express = await frontends.expressInstance()
await frontends.expressConfigure(express)
await frontends.expressRoutes(express)
await frontends.expressErrors(express)
let server = await frontends.serverInstance(express)
await frontends.serverListen(server)
let io = await sockets.instance(server)
let slack = {}
sockets.listen(db, io, slack)
let token = await datastores.getSlackToken(db)
let restart = await slacks.restart(slack, token)
if (restart.done === true) {
slacks.listen(db, io, slack)
}
if (restart.done === false) {
io.emit(`slackRestartFailed`, `${restart.message}`)
}
console.log(await funs.graffiti())
} catch (err) {
console.log(err)
}
}
// https://medium.com/@dtinth/making-unhandled-promise-rejections-crash-the-node-js-process-ffc27cfcc9dd
// process.on(`unhandledRejection`, up => { throw up })
if (require.main === module) main()
module.exports = {
main: main
}