Skip to content

Instantly share code, notes, and snippets.

@alessioalex
Created July 7, 2011 19:54
Show Gist options
  • Save alessioalex/1070395 to your computer and use it in GitHub Desktop.
Save alessioalex/1070395 to your computer and use it in GitHub Desktop.
var http = require('http'),
faye = require('faye'),
fs = require('fs'),
path = require('path');
var bayeux = new faye.NodeAdapter({
mount: '/faye',
timeout: 45
});
var PUBLIC_DIR = path.dirname(__filename);
// Handle non-Bayeux requests
var server = http.createServer(function(req, res) {
var path = (req.url === '/') ? '/index.html' : req.url;
fs.readFile(PUBLIC_DIR + path, function(err, content) {
var status = err ? 404 : 200;
res.writeHead(status, {'Content-Type': 'text/html'});
res.write(content || 'Not found');
res.end();
});
});
bayeux.attach(server);
server.listen(8000);
var client = new Faye.Client('http://localhost:8000/faye');
client.subscribe('/messages', function(message) {
console.log('SS: ' + message.text);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment