diff --git a/swarmlab-app/src/run/app.js b/swarmlab-app/src/run/app.js index ed5680a..0d99d89 100755 --- a/swarmlab-app/src/run/app.js +++ b/swarmlab-app/src/run/app.js @@ -291,50 +291,51 @@ app.get('/get_log', [ cors(corsOptions), (req, res, next) => { (async() => { - -var mongourl = "mongodb://"+CONFIG.mongo.user+":"+CONFIG.mongo.password+"@ondemand_playground_mongo1:27017,ondemand_playground_mongo2:27017,ondemand_playground_mongo3:27017,ondemand_playground_mongo4:27017,ondemand_playground_mongo5:27017,ondemand_playground_mongo6:27017,ondemand_playground_mongo7:27017/fluent?replicaSet=rs1&authSource=swarmlabplaygroundstats" -const OPTS = { - useNewUrlParser: true, - useUnifiedTopology: true -}; -MongoClient.connect(mongourl, OPTS, function(err, client){ - if(err){ - console.log(err); - } else { - const db = client.db('fluent'); - //db.collection('log', onCollection); - console.log(JSON.stringify('mongo connected')) - var stream = db.collection('logs').find({}, { - tailable: true, - awaitdata: true - }).stream(); - - stream.on('data', function (doc) { - console.log(JSON.stringify(doc)) - //socket.write(JSON.stringify({'action': 'log','param': doc.log})); - - - var RES = new Object(); - RES.token = req.query["token"] - RES.start = req.query["start"] - RES.end = req.query["end"] - RES.filter = req.query["filter"] - var isvalid = await checkToken(RES.token); - if(isvalid.action == 'ok'){ - console.log("Authserver ok " + RES.token); - RES.error = 'ok' - }else{ - console.log("Authserver no " + RES.token); - RES.error = 'no' + var RES = new Object(); + RES.token = req.query["token"] + RES.start = req.query["start"] + RES.end = req.query["end"] + RES.filter = req.query["filter"] + var isvalid = await checkToken(RES.token); + if(isvalid.action == 'ok'){ + console.log("Authserver ok " + RES.token); + RES.error = 'ok' + }else{ + console.log("Authserver no " + RES.token); + RES.error = 'no' + } +if(RES.error == 'ok'){ + var mongourl = "mongodb://"+CONFIG.mongo.user+":"+CONFIG.mongo.password+"@ondemand_playground_mongo1:27017,ondemand_playground_mongo2:27017,ondemand_playground_mongo3:27017,ondemand_playground_mongo4:27017,ondemand_playground_mongo5:27017,ondemand_playground_mongo6:27017,ondemand_playground_mongo7:27017/fluent?replicaSet=rs1&authSource=swarmlabplaygroundstats" + const OPTS = { + useNewUrlParser: true, + useUnifiedTopology: true + }; + MongoClient.connect(mongourl, OPTS, function(err, client){ + if(err){ + console.log(err); + } else { + const db = client.db('fluent'); + //db.collection('log', onCollection); + console.log(JSON.stringify('mongo connected')) + var stream = db.collection('logs').find({}, { + tailable: true, + awaitdata: true + }).stream(); + + stream.on('data', function (doc) { + console.log(JSON.stringify(doc)) + //socket.write(JSON.stringify({'action': 'log','param': doc.log})); + RES.error_msg = "ok" + res.json(RES) + }); } - RES.error_msg = "ok" - res.json(RES) - + }); +}else{ +RES.error_msg = "tokeni err" +res.json(RES) - }); - } -}); +} })()