-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (30 loc) · 1.18 KB
/
index.js
File metadata and controls
41 lines (30 loc) · 1.18 KB
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
const dotenv = require('dotenv');
dotenv.config();
const MongoClient = require('mongodb').MongoClient;
const WebSocket = require('ws');
let wss = null;
const ConnectionsModule = require("./Connection.js");
const Connection = ConnectionsModule.Connection;
const initDbCollections = ConnectionsModule.initDbCollections;
/**
* Create the database client used to create collections connections.
*/
const dbUsername = process.env['ATLAS_DB_USERNAME'];
const dbPassword = process.env['ATLAS_DB_PASSWORD'];
const dbUri = `mongodb+srv://${dbUsername}:${dbPassword}@cluster-ishbilia.oskgm.mongodb.net?retryWrites=true&w=majority&tls=true`;
const dbClient = new MongoClient(dbUri, { useUnifiedTopology: true, tls: true});
dbClient.connect( (error) => {
if(error){
console.log("Failed to connect to Database server: ", error.message);
throw error;
}
initDbCollections(dbClient);
wss = new WebSocket.Server({ port: process.env.PORT || 3000 , host: "0.0.0.0"});
wss.on("listening", ()=>{
console.log("The server is running.");
});
wss.on('connection', function connection(ws, request) {
console.log("New Connection")
const newConnection = new Connection(ws);
});
});