Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
486663d
commit 3d0fb81
Showing
10 changed files
with
150 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,3 +71,4 @@ server/.idea/Server.iml | |
server/.nyc_output | ||
server/coverage | ||
ExampleNodeJS.code-workspace | ||
server/upload/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<html> | ||
<head><title>Send</title></head> | ||
<body> | ||
Invia un messaggio a <a href="server/public/ricevi.html">ricevi.html</a><br> | ||
<input type="text"> | ||
<button >Send</button> | ||
</body> | ||
<script | ||
src="https://code.jquery.com/jquery-3.3.1.min.js" | ||
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" | ||
crossorigin="anonymous"></script> | ||
|
||
<script> | ||
$("button").click(function() { | ||
$.ajax({ | ||
url: 'observer/listen', | ||
type: 'POST', | ||
data: {msg: $("input").val()}, | ||
}); | ||
}); | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<html> | ||
<head><title>Receive</title></head> | ||
<body> | ||
Riceve il messaggio inviato da <a href="server/public/invia.html">invia.html</a> | ||
<br><span>Messaggio: </span><p></p> | ||
</body> | ||
<script | ||
src="https://code.jquery.com/jquery-3.3.1.min.js" | ||
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" | ||
crossorigin="anonymous"></script> | ||
|
||
<script> | ||
setInterval(function(){ | ||
$.ajax({ | ||
url: 'observer/response', | ||
type: 'GET', | ||
success: function(done){ | ||
$("p").html(done.msg); | ||
} | ||
}); | ||
}, 30000); | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
let express = require('express'); | ||
let router = express.Router(); | ||
const EventEmitter = require('events'); | ||
|
||
class MyEmitter extends EventEmitter{} | ||
|
||
let myEmitter = new MyEmitter(); | ||
let obj; | ||
|
||
router.post('/listen', function(req, res){ | ||
let i=0; | ||
obj = req.body; | ||
myEmitter.once('sendmsg', () => {//.on resta sempre in ascolto | ||
if(obj.msg==="inc"){ | ||
i++; | ||
} | ||
else{ | ||
i--; | ||
} | ||
}); | ||
myEmitter.emit('sendmsg'); | ||
res.send({msg: i}); | ||
}); | ||
|
||
router.get('/response', function(req, res){ | ||
myEmitter.emit('sendmsg'); | ||
res.send({msg:obj.msg}); | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
process.env.NODE_ENV = 'test'; | ||
|
||
let expect = require('chai').expect; | ||
let chai = require('chai'); | ||
let chaiHttp = require('chai-http'); | ||
let randomstring = require("randomstring"); | ||
let server = require('../app'); | ||
// eslint-disable-next-line no-unused-vars | ||
let should = chai.should(); | ||
chai.use(require('chai-match')); | ||
chai.use(chaiHttp); | ||
|
||
it('POST: it should response with a object', function(done){ | ||
let obj= {msg: randomstring.generate(3)}; | ||
chai.request(server) | ||
.post('/observer/listen') | ||
.send(obj) | ||
.end(function(err, res){ | ||
res.should.have.status(200); | ||
expect(res.body).to.be.an('object'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('POST: it should response with a object', function(done){ | ||
let obj= {msg: "inc"}; | ||
chai.request(server) | ||
.post('/observer/listen') | ||
.send(obj) | ||
.end(function(err, res){ | ||
res.should.have.status(200); | ||
expect(res.body).to.be.an('object'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('GET: it should response with a string', function(done){ | ||
|
||
chai.request(server) | ||
.get('/observer/response') | ||
.end(function(err, res){ | ||
res.should.have.status(200); | ||
expect(res.body).to.be.an('object'); | ||
done(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3d0fb81
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong commit message, I want to say init observer