-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
35 lines (29 loc) · 868 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var http = require('http'),
express = require('express'),
bodyParser = require('body-parser'),
faye = require('faye'),
app = express(),
server = http.createServer(app);
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(express['static'](__dirname + '/public'));
var ws = new faye.NodeAdapter({
mount: '/faye',
timeout: 45
});
ws.attach(server);
app.post('/message', function(req, res) {
ws.getClient().publish('/channel', {
text: req.body.message
});
console.log('broadcast message:' + req.body.message);
res.send(200);
});
app.get('/', function(req, res) {
res.send(200).status({message: 'hi mate, you have hit the root route'});
});
var port = process.env.PORT || 8181;
server.listen(port, function() {
console.log('Express server listening on port ' + port);
});