zeus
3 years ago
12 changed files with 62 additions and 1512 deletions
@ -1 +0,0 @@ |
|||
Course examples |
@ -1,31 +0,0 @@ |
|||
|
|||
const app = require('express')(); |
|||
const http = require('http').Server(app); |
|||
var path = require('path'); |
|||
|
|||
options = { |
|||
secure:true, |
|||
reconnect: true, |
|||
rejectUnauthorized : false |
|||
}; |
|||
|
|||
|
|||
var io2 = require('socket.io-client'); |
|||
var socket = io2.connect('http://localhost:8084', options); |
|||
|
|||
var msg2 = "c= 120"; |
|||
socket.emit('log', msg2); |
|||
|
|||
/* |
|||
var io = require('socket.io')(http); |
|||
|
|||
app.get('/log', (req, res) => { |
|||
socket.emit('log', 'send from get'); |
|||
res.send('<h1>send</h1>'); |
|||
}); |
|||
|
|||
http.listen(8085, () => { |
|||
console.log('listening on *:8085'); |
|||
}); |
|||
*/ |
|||
|
@ -1,109 +0,0 @@ |
|||
var path = require('path'); |
|||
var app = require('express')(); |
|||
var http = require('http').Server(app); |
|||
var io = require('socket.io')(http); |
|||
const MongoClient = require('mongodb').MongoClient; |
|||
|
|||
|
|||
app.get('/test', (req, res) => { |
|||
|
|||
var user="swarmlab" |
|||
var pass="swarmlab" |
|||
|
|||
/* |
|||
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+"@swarmlabmongo1:27017,swarmlabmongo2:27017,swarmlabmongo1:27017/app_swarmlab?replicaSet=rs0&authSource=admin&w=1" |
|||
const OPTS = { |
|||
useNewUrlParser: true, |
|||
useUnifiedTopology: true, |
|||
//poolSize: 10,
|
|||
tls: false |
|||
}; |
|||
|
|||
const client = new MongoClient(mongourl,OPTS); |
|||
|
|||
client.on('serverDescriptionChanged', function(event) { |
|||
console.log('received serverDescriptionChanged'); |
|||
console.log(JSON.stringify(event, null, 2)); |
|||
}); |
|||
|
|||
client.on('serverHeartbeatStarted', function(event) { |
|||
console.log('received serverHeartbeatStarted'); |
|||
console.log(JSON.stringify(event, null, 2)); |
|||
}); |
|||
|
|||
client.on('serverHeartbeatSucceeded', function(event) { |
|||
console.log('received serverHeartbeatSucceeded'); |
|||
console.log(JSON.stringify(event, null, 2)); |
|||
}); |
|||
|
|||
client.on('serverHeartbeatFailed', function(event) { |
|||
console.log('received serverHeartbeatFailed'); |
|||
console.log(JSON.stringify(event, null, 2)); |
|||
}); |
|||
|
|||
client.on('serverOpening', function(event) { |
|||
console.log('received serverOpening'); |
|||
console.log(JSON.stringify(event, null, 2)); |
|||
}); |
|||
|
|||
client.on('serverClosed', function(event) { |
|||
console.log('received serverClosed'); |
|||
console.log(JSON.stringify(event, null, 2)); |
|||
}); |
|||
|
|||
client.on('topologyOpening', function(event) { |
|||
console.log('received topologyOpening'); |
|||
console.log(JSON.stringify(event, null, 2)); |
|||
}); |
|||
|
|||
client.on('topologyClosed', function(event) { |
|||
console.log('received topologyClosed'); |
|||
console.log(JSON.stringify(event, null, 2)); |
|||
}); |
|||
|
|||
client.on('topologyDescriptionChanged', function(event) { |
|||
console.log('received topologyDescriptionChanged'); |
|||
console.log(JSON.stringify(event, null, 2)); |
|||
}); |
|||
|
|||
client.connect(function(err, client) { |
|||
if(err) throw err; |
|||
|
|||
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>Hello world!</h1>'); |
|||
}); |
|||
|
|||
io.on('connection', s => { |
|||
console.error('socket connection'); |
|||
|
|||
s.on('log', (data, room) => { |
|||
console.log('broadcast', data); |
|||
}); |
|||
|
|||
}); |
|||
|
|||
http.listen(8084, () => console.error('listening on http://localhost:8084/')); |
|||
console.error('socket.io example'); |
@ -1,24 +0,0 @@ |
|||
var path = require('path'); |
|||
var app = require('express')(); |
|||
var http = require('http').Server(app); |
|||
var io = require('socket.io')(http); |
|||
|
|||
|
|||
app.get('/', (req, res) => { |
|||
res.send('<h1>Hello world!</h1>'); |
|||
}); |
|||
|
|||
|
|||
io.on('connection', s => { |
|||
console.error('socket connection'); |
|||
|
|||
s.on('log', (data, room) => { |
|||
console.log('broadcast', data); |
|||
}); |
|||
|
|||
|
|||
}); |
|||
|
|||
|
|||
http.listen(8084, () => console.error('listening on http://localhost:8084/')); |
|||
console.error('socket.io example'); |
@ -1,8 +0,0 @@ |
|||
{ |
|||
"dependencies": { |
|||
"express": "^4.17.1", |
|||
"mongodb": "^3.6.5", |
|||
"socket.io": "^4.0.0", |
|||
"socket.io-client": "^4.0.0" |
|||
} |
|||
} |
@ -1,107 +0,0 @@ |
|||
var express = require('express'); |
|||
var http = require('http'); |
|||
const MongoClient = require('mongodb').MongoClient; |
|||
|
|||
var PORT = 8085; |
|||
|
|||
var app = express(); |
|||
app.get('/', function(req, res) { |
|||
var RES ={} |
|||
var message = req.query["log"] |
|||
|
|||
// Connection URL
|
|||
var database = "app_swarmlab" |
|||
var user = "swarmlab" |
|||
var password = "swarmlab" |
|||
var collection = "logs" |
|||
var replica_set = "rs0" |
|||
var nodes = "swarmlabmongo1:27017,swarmlabmongo2:27017,swarmlabmongo3:27017" |
|||
//var url = `mongodb://${user}:${password}@${nodes}/${database}?replicaSet=${replica_set}&authSource=admin`
|
|||
|
|||
var mongourl = "mongodb://"+user+":"+password+"@swarmlabmongo1:27017,swarmlabmongo2:27017,swarmlabmongo3:27017/app_swarmlab?replicaSet=rs0&authSource=admin&w=1" |
|||
const OPTS = { |
|||
useNewUrlParser: true, |
|||
useUnifiedTopology: true, |
|||
//poolSize: 10,
|
|||
tls: false |
|||
}; |
|||
|
|||
const client = new MongoClient(mongourl,OPTS); |
|||
|
|||
client.on('serverDescriptionChanged', function(event) { |
|||
console.log('received serverDescriptionChanged'); |
|||
console.log(JSON.stringify(event, null, 2)); |
|||
}); |
|||
|
|||
client.on('serverHeartbeatStarted', function(event) { |
|||
console.log('received serverHeartbeatStarted'); |
|||
console.log(JSON.stringify(event, null, 2)); |
|||
}); |
|||
|
|||
client.on('serverHeartbeatSucceeded', function(event) { |
|||
console.log('received serverHeartbeatSucceeded'); |
|||
console.log(JSON.stringify(event, null, 2)); |
|||
}); |
|||
|
|||
client.on('serverHeartbeatFailed', function(event) { |
|||
console.log('received serverHeartbeatFailed'); |
|||
console.log(JSON.stringify(event, null, 2)); |
|||
}); |
|||
|
|||
client.on('serverOpening', function(event) { |
|||
console.log('received serverOpening'); |
|||
console.log(JSON.stringify(event, null, 2)); |
|||
}); |
|||
|
|||
client.on('serverClosed', function(event) { |
|||
console.log('received serverClosed'); |
|||
console.log(JSON.stringify(event, null, 2)); |
|||
}); |
|||
|
|||
client.on('topologyOpening', function(event) { |
|||
console.log('received topologyOpening'); |
|||
console.log(JSON.stringify(event, null, 2)); |
|||
}); |
|||
|
|||
client.on('topologyOpening', function(event) { |
|||
console.log('received topologyOpening'); |
|||
console.log(JSON.stringify(event, null, 2)); |
|||
}); |
|||
|
|||
client.on('topologyClosed', function(event) { |
|||
console.log('received topologyClosed'); |
|||
console.log(JSON.stringify(event, null, 2)); |
|||
}); |
|||
|
|||
client.on('topologyDescriptionChanged', function(event) { |
|||
console.log('received topologyDescriptionChanged'); |
|||
console.log(JSON.stringify(event, null, 2)); |
|||
}); |
|||
|
|||
client.connect(function(err, client) { |
|||
if(err) throw err; |
|||
|
|||
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({message: message, data:item}); |
|||
|
|||
}) |
|||
}); |
|||
}); |
|||
|
|||
app.post('/', function(req, res) { |
|||
var message = req.body["log"] |
|||
console.log(JSON.stringify(message)) |
|||
//console.log(req)
|
|||
res.send({message: message}); |
|||
}); |
|||
|
|||
http.Server(app).listen(PORT, function() { |
|||
console.log("HTTP server listening on port %s", PORT); |
|||
}); |
|||
|
File diff suppressed because it is too large
@ -1,7 +0,0 @@ |
|||
{ |
|||
"main": "app.js", |
|||
"dependencies": { |
|||
"express": "^4.17.1", |
|||
"mongodb": "^3.6.6" |
|||
} |
|||
} |
@ -1,121 +0,0 @@ |
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
|||
|
|||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> |
|||
<head> |
|||
<title>Test Page for the Nginx HTTP Server on Swarmlab.io</title> |
|||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
|||
<style type="text/css"> |
|||
/*<![CDATA[*/ |
|||
body { |
|||
background-color: #fff; |
|||
color: #000; |
|||
font-size: 0.9em; |
|||
font-family: sans-serif,helvetica; |
|||
margin: 0; |
|||
padding: 0; |
|||
} |
|||
:link { |
|||
color: #c00; |
|||
} |
|||
:visited { |
|||
color: #c00; |
|||
} |
|||
a:hover { |
|||
color: #f50; |
|||
} |
|||
h1 { |
|||
text-align: center; |
|||
margin: 0; |
|||
padding: 0.6em 2em 0.4em; |
|||
background-color: #294172; |
|||
color: #fff; |
|||
font-weight: normal; |
|||
font-size: 1.75em; |
|||
border-bottom: 2px solid #000; |
|||
} |
|||
h1 strong { |
|||
font-weight: bold; |
|||
font-size: 1.5em; |
|||
} |
|||
h2 { |
|||
text-align: center; |
|||
background-color: #3C6EB4; |
|||
font-size: 1.1em; |
|||
font-weight: bold; |
|||
color: #fff; |
|||
margin: 0; |
|||
padding: 0.5em; |
|||
border-bottom: 2px solid #294172; |
|||
} |
|||
hr { |
|||
display: none; |
|||
} |
|||
.content { |
|||
padding: 1em 5em; |
|||
} |
|||
.alert { |
|||
border: 2px solid #000; |
|||
} |
|||
|
|||
img { |
|||
border: 2px solid #fff; |
|||
padding: 2px; |
|||
margin: 2px; |
|||
} |
|||
a:hover img { |
|||
border: 2px solid #294172; |
|||
} |
|||
.logos { |
|||
margin: 1em; |
|||
text-align: center; |
|||
} |
|||
/*]]>*/ |
|||
</style> |
|||
</head> |
|||
|
|||
<body> |
|||
<h1>Welcome to <strong>nginx</strong> on Swarmlab.io!</h1> |
|||
|
|||
<div class="content"> |
|||
<p>This page is used to test the proper operation of the |
|||
<strong>nginx</strong> HTTP server after it has been |
|||
installed. If you can read this page, it means that the |
|||
web server installed at this site is working |
|||
properly.</p> |
|||
|
|||
<div class="alert"> |
|||
<h2>Website Administrator</h2> |
|||
<div class="content"> |
|||
<p>This is the default <tt>index.html</tt> page that |
|||
is distributed with <strong>nginx</strong> on |
|||
Swarmlab.io. It is located in |
|||
<tt>/data/www</tt>.</p> |
|||
|
|||
<p>You should now put your content in a location of |
|||
your choice and edit the <tt>root</tt> configuration |
|||
directive in the <strong>nginx</strong> |
|||
configuration file |
|||
<tt>/etc/nginx/nginx.conf</tt>.</p> |
|||
|
|||
<a href="https://docs.nginx.com/nginx/admin-guide/web-server/serving-static-content/"> |
|||
<img |
|||
src="nginx-logo.png" |
|||
alt="[ Powered by nginx ]" |
|||
width="121" height="32" />More info here</a> |
|||
</div> |
|||
</div> |
|||
|
|||
<div class="logos"> |
|||
<a href="http://nginx.com/"><img |
|||
src="nginx-logo.png" |
|||
alt="[ Powered by nginx ]" |
|||
width="121" height="32" /></a> |
|||
|
|||
<a href="http://swarmlab.io"><img |
|||
src="poweredby.png" |
|||
alt="[ Powered by Swarmlab.io ]" |
|||
width="88" height="31" /></a> |
|||
</div> |
|||
</div> |
|||
</body> |
|||
</html> |
@ -1 +0,0 @@ |
|||
echo "Hello World" |
Loading…
Reference in new issue