-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
55 lines (45 loc) · 1.55 KB
/
server.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
const server = require("http").createServer();
const { Server } = require("socket.io");
const { instrument } = require("@socket.io/admin-ui");
// Service Start Message
console.log('\nbcdLab Communication Server Started\n');
// ------------ Prepare Configs ------------ //
const config = require('./config')();
// ------------ Prepare Socket.IO Server with CORS ------------ //
const io = new Server(server, {
cors: {
origin: config.cors,
credentials: true
}
});
// ------------ Prepare and Start Metrics Server ------------ //
const MetricServer = require('./src/MetricsServer');
const metric = new MetricServer();
metric.start();
// ------------ Prepare and Connect to Database ------------ //
const DataBase = require('./src/Database');
const db = new DataBase();
db.connect();
// Reset currently running nodes
db.resetNodes();
// ------------ Define NameSpaces ------------ //
require('./src/Namespaces/nodes')(io,metric.namespaceEvents,db.namespaces.nodes);
//require('./src/Namespaces/web')(io,metric.namespaceEvents,db);
// Refuse Main NameSpace Connections
io.use((socket, next) => {
return next(new Error("Not Authorized"));
});
// ------------ Config for Admin UI ------------ //
instrument(io, {
auth: {
type: "basic",
username: config.webUi_username,
password: config.webUi_password // "changeit" encrypted with bcrypt
},
readonly: config.webUi_readonly,
mode: config.webUi_mode,
});
// ------------ Start the Server ------------ //
server.listen(3000, () => {
console.log('socket.io Server listening on *:3000\n');
});