From d5107ea1b5f3113dfddfb4fc3a797a60cd4cb77f Mon Sep 17 00:00:00 2001 From: zeus Date: Sun, 28 Mar 2021 20:05:00 +0300 Subject: [PATCH] add example --- .../example-helloworld/app/helloworld.js | 90 ------------------- .../usr/share/swarmlab.io/sec/swarmlab-sec | 2 - 2 files changed, 92 deletions(-) delete mode 100644 install/usr/share/swarmlab.io/sec/project/courses/example-helloworld/app/helloworld.js diff --git a/install/usr/share/swarmlab.io/sec/project/courses/example-helloworld/app/helloworld.js b/install/usr/share/swarmlab.io/sec/project/courses/example-helloworld/app/helloworld.js deleted file mode 100644 index 14b15f3..0000000 --- a/install/usr/share/swarmlab.io/sec/project/courses/example-helloworld/app/helloworld.js +++ /dev/null @@ -1,90 +0,0 @@ -const app = require('express')(); -const http = require('http').Server(app); -var path = require('path'); -var io = require('socket.io')(http); -const MongoClient = require('mongodb').MongoClient; - - -app.get('/', (req, res) => { - res.send('

Hello world!

'); -}); - -app.get('/test', (req, res) => { - - - var user="test1" - var pass="newpass" - //mongo “mongodb://localhost:30001,localhost:30002,localhost:30003/$MONGO_INITDB_DATABASE” -u $MONGO_INITDB_USERNAME mongo “mongodb://localhost:30001,localhost:30002,localhost:30003/app_swarmlab” -u app_swarmlab - //mongodb://host1:27017,host2:27017,host3:27017/?replicaSet=myRs - //var mongourl = "mongodb://"+user+":"+pass+"@localhost:30001,localhost:30002,localhost:30003/app_swarmlab?replicaSet=rs0&authSource=admin" - /* - use admin -db.createUser( - { - user: "test1", - pwd: 'newpass', // Or "" - roles: [ { role: "readWrite", db: "app_swarmlab" } ], - authenticationRestrictions: [ { - clientSource: ["192.168.1.7"], - serverAddress: ["192.168.80.2", "192.168.80.3", "192.168.80.4"] - } ] - } -) -*/ - - var mongourl = "mongodb://"+user+":"+pass+"@192.168.80.2:27017/app_swarmlab?replicaSet=rs0&authSource=admin" - const OPTS = { - useNewUrlParser: true, - useUnifiedTopology: true - }; -var options = { - useNewUrlParser: true, - useUnifiedTopology: true -} - - - MongoClient.connect(mongourl, options, function(err, client){ - if(err){ - console.log(err); - } else { - console.log(JSON.stringify('mongo ----------------connected')) - const db = client.db('app_swarmlab'); - db.collection('logs').find({}).toArray() - .then(item => { - console.log('item '+JSON.stringify(item)) - for (let i in item) { - console.log(JSON.stringify('items' + item[i])) - } - }) - - } - }) - res.send('

test!

'); - -}); - - - - - -io.on('connection', s => { - console.error('socket connection'); - - s.on('log', (data, room) => { - s.to('iot').emit('message', data); - console.log('broadcast', data); - - }); - //s.emit('message', 'message from server'); - - - -}); - - - - - -http.listen(8084, () => { - console.log('listening on *:8084'); -}); diff --git a/install/usr/share/swarmlab.io/sec/swarmlab-sec b/install/usr/share/swarmlab.io/sec/swarmlab-sec index dbf051c..4641eec 100755 --- a/install/usr/share/swarmlab.io/sec/swarmlab-sec +++ b/install/usr/share/swarmlab.io/sec/swarmlab-sec @@ -334,7 +334,6 @@ services: - ${HYBRID_NETWORK} volumes: - $Wdir/project:/home/docker/project - - /tmp/.X11-unix:/tmp/.X11-unix worker: @@ -352,7 +351,6 @@ services: - ${HYBRID_NETWORK} volumes: - $Wdir/project:/home/docker/project - - /tmp/.X11-unix:/tmp/.X11-unix networks: ${HYBRID_NETWORK}: