Browse Source

edit

master
zeus 4 years ago
parent
commit
d58a5a7afd
  1. 75
      swarmlab-app/src/run/app.js

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

@ -2,9 +2,16 @@ 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);
//var MongoClient = require('mongodb').MongoClient;
//const socketAuth = require('socketio-auth'); var async = require("async");
const { check, validationResult } = require('express-validator');
const urlExistSync = require("url-exist-sync");
var express = require('express');
app.use(express.json());
const helmet = require('helmet');
app.use(helmet());
const cors = require('cors') const cors = require('cors')
const whitelist = [ const whitelist = [
@ -57,56 +64,34 @@ app.post('/run', [
//check('llo').isBase64() //check('llo').isBase64()
], ],
cors(corsOptions), (req, res, next) => { cors(corsOptions), (req, res, next) => {
console.error('socket POST from client');
var RES = new Object();
RES.error = false
RES.error_msg = "ok"
res.json(RES)
});
// ------------------------------------------------ //console.log(JSON.stringify(req.headers));
/* //console.log(JSON.stringify(req.body));
var mongouser = "playgrounduser"; console.log("mongo "+JSON.stringify(req.body));
var mongopass = "efvvnuioervefSDFSGYGHRDFVsdfergvssppiiedifhwincvinviw_dbfjbsifbsdkjfswuunscfudfgbbfvibqefwrvnine"; console.log("LOG "+JSON.stringify(req.body[0].message));
const mongourl = 'mongodb://'+mongouser+':'+mongopass+'@node1:27017/?replicaSet=rs0'; console.log("PATH "+JSON.stringify(req.body[0].tailed_path));
const dbNameedit = 'swarmlab_playground_logs'; for (var i = 0; i < req.body.length; i++){
var obj = req.body[i];
var mongooption = { var reslog = new Object();
server: { for (var key in obj){
reconnectTries: Number.MAX_VALUE, var value = obj[key];
reconnectInterval: 1000 //console.log("line " + key + ": " + value);
reslog.key = key
reslog.value = value
io.emit("logdata", reslog);
} }
} }
// Create a new MongoClient
const client = new MongoClient(mongourl, mongooption);
var dbName;
function findDocuments(db, callback) {
const collection = db.collection( 'devel_log' );
collection.find().toArray(function(err, docs) {
console.log("Found the following records");
console.log(docs)
callback(docs);
});
}
//io.in("iot").emit("message", RES);
console.error('socket POST from client');
var RES = new Object();
RES.error = false
RES.error_msg = "ok"
RES.msg = req.body[0].messsage
// Use connect method to connect to the Server res.json(RES)
client.connect(function(err) {
console.log("Connected correctly to server");
dbName = client.db(dbNameedit);
findDocuments(dbName, function() {
//client.close();
});
}); });
*/
io.origins('*:*') // for latest version io.origins('*:*') // for latest version

Loading…
Cancel
Save