Browse Source

add example

master
zeus 4 years ago
parent
commit
d5107ea1b5
  1. 90
      install/usr/share/swarmlab.io/sec/project/courses/example-helloworld/app/helloworld.js
  2. 2
      install/usr/share/swarmlab.io/sec/swarmlab-sec

90
install/usr/share/swarmlab.io/sec/project/courses/example-helloworld/app/helloworld.js

@ -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('<h1>Hello world!</h1>');
});
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 "<cleartext password>"
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('<h1>test!</h1>');
});
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');
});

2
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}:

Loading…
Cancel
Save