diff --git a/swarmlab-app/package.json b/swarmlab-app/package.json index d2cc99f..c597da1 100644 --- a/swarmlab-app/package.json +++ b/swarmlab-app/package.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "axios": "^0.21.0", + "mongodb": "^3.6.3", "cors": "^2.8.5", "express": "^4.17.1", "helmet": "^4.2.0", diff --git a/swarmlab-app/src/run/app.js b/swarmlab-app/src/run/app.js index b294628..dcebffc 100644 --- a/swarmlab-app/src/run/app.js +++ b/swarmlab-app/src/run/app.js @@ -2,6 +2,7 @@ var path = require('path'); var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); +vat MongoClient = require('mongodb').MongoClient; //const socketAuth = require('socketio-auth'); @@ -63,7 +64,45 @@ cors(corsOptions), (req, res, next) => { res.json(RES) }); - +// ------------------------------------------------ +var mongouser = "playgrounduser"; +var mongopass = "efvvnuioervefSDFSGYGHRDFVsdfergvssppiiedifhwincvinviw_dbfjbsifbsdkjfswuunscfudfgbbfvibqefwrvnine"; +const mongourl = 'mongodb://'+mongouser+':'+mongopass+'@node1:27017,node2:27017/?replicaSet=rs0'; +const dbNameedit = 'swarmlab_playground_logs'; +var dbName; +// Initialize connection once +MongoClient.connect(mongourl, function(err, database) { + if(err) throw err; + //dbName = database; + dbName = dayabase.db('swarmlab_playground_logs'); +}); + + + dbName.collection("devel_log").find({}, function(err, docs) { + +docs.each(function(err, doc) { + if(doc) { + console.log(doc); + } + else { + res.end(); + } + }); + + + + }); + +/* +MongoClient.connect(mongourl, options).then((client) => { + dbName = client.db('swarmlab_playground_logs'); + // do database things +}).catch((error) => { + // handle connection errors +}); +*/ + + io.origins('*:*') // for latest version io.on('connection', s => {