Browse Source

add mongodb

master
zeus 4 years ago
parent
commit
e602c6d356
  1. 1
      swarmlab-app/package.json
  2. 39
      swarmlab-app/src/run/app.js

1
swarmlab-app/package.json

@ -10,6 +10,7 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"axios": "^0.21.0", "axios": "^0.21.0",
"mongodb": "^3.6.3",
"cors": "^2.8.5", "cors": "^2.8.5",
"express": "^4.17.1", "express": "^4.17.1",
"helmet": "^4.2.0", "helmet": "^4.2.0",

39
swarmlab-app/src/run/app.js

@ -2,6 +2,7 @@ var path = require('path');
var app = require('express')(); var app = require('express')();
var http = require('http').Server(app); var http = require('http').Server(app);
var io = require('socket.io')(http); var io = require('socket.io')(http);
vat MongoClient = require('mongodb').MongoClient;
//const socketAuth = require('socketio-auth'); //const socketAuth = require('socketio-auth');
@ -63,6 +64,44 @@ cors(corsOptions), (req, res, next) => {
res.json(RES) 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.origins('*:*') // for latest version

Loading…
Cancel
Save