Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

aggiunto setHeader, canale alertTecnico (con log in console)

  • Loading branch information...
commit 61f2c69cae8fbc11fcc51b95b8a918940b25b6dd 1 parent 2058f55
@mikosh75 authored
Showing with 23 additions and 26 deletions.
  1. +0 −25 public/client.html
  2. +23 −1 server.js
View
25 public/client.html
@@ -1,25 +0,0 @@
-<html>
- <body>
- <h1>NodeCasts.org - Realtime pubsub with Faye Channel 1</h1>
- <div id="messages"></div>
-
- <script src="/jquery-1.6.3.min.js"></script>
- <script src="/faye.js"></script>
-
- <script type="text/javascript">
-
- var client = new Faye.Client('/faye', {
- timeout: 120
- });
-
- client.subscribe('/channel/1', function(message) {
- $("#messages").append("<p>" + message.text1 + "</p>");
- });
-
- //subscription.callback(function() {
- // alert('Subscription is now active!');
- // });
-
- </script>
- </body>
-</html>
View
24 server.js
@@ -9,10 +9,18 @@ var bayeux = new faye.NodeAdapter({
var app = express.createServer();
+setHeaders = function (req,res,next) {
+ res.header("X-Powered-By","nodejs");
+ res.header("Access-Control-Allow-Origin",req.header('origin'));
+ res.header("Access-Control-Allow-Headers", "X-Requested-With");
+ next();
+}
+
app.configure(function(){
//app.use(express.logger({ format: ':method :url' }));
app.use(express.bodyParser());
app.use(express.methodOverride());
+ app.use(setHeaders);
app.use(app.router);
});
@@ -37,6 +45,15 @@ app.post('/message', function(req, res) {
res.send(200);
});
+app.post('/alert_tecnico', function(req, res) {
+ bayeux.getClient().publish('/channel/' + req.body.ch, { id_chat : req.body.id_chat,
+ ch: req.body.ch
+ }
+ );
+ res.send(200);
+});
+
+
app.get('/', function(req, res){
res.send('hello world');
});
@@ -50,5 +67,10 @@ app.listen(Number(port));
console.log('Listening on port ' + port );
bayeux.getClient().subscribe('/channel/*', function(message) {
- console.log(message.timestamp + ' [' + message.ch + '] ' + message.clientid + ' ' + message.text);
+ if (message.ch=="T3"){
+ var ts = (new Date()).getTime();
+ console.log(ts + ' [' + message.ch + '] ' + message.id_chat);
+ } else {
+ console.log(message.timestamp + ' [' + message.ch + '] ' + message.clientid + ' ' + message.text);
+ }
});
Please sign in to comment.
Something went wrong with that request. Please try again.