-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
44 lines (34 loc) · 935 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
36
37
38
39
40
41
42
43
44
//jjangg96
//simple faye server for node.js
var http = require('http'),
faye = require('faye'),
port = 8888;
var bayeux = new faye.NodeAdapter({mount: '/faye', timeout: 45});
// Handle non-Bayeux requests
var server = http.createServer(function(request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello, non-Bayeux request');
});
exports.start = function start(custom_server, publish_callback)
{
if(custom_server == null)
{
bayeux.attach(server);
server.listen(port);
}
else
{
bayeux.attach(custom_server);
custom_server.listen(port);
}
console.log('faye server started, port ' + port);
exports.client = bayeux.getClient();
if(publish_callback != null)
{
bayeux.on('publish', publish_callback);
}
}
//Error catch
process.on('uncaughtException', function (err) {
console.log('[' + new Date() + '][Error] ' + err.stack);
});