Skip to content

Instantly share code, notes, and snippets.

@shripadk
Created November 28, 2011 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shripadk/1400312 to your computer and use it in GitHub Desktop.
Save shripadk/1400312 to your computer and use it in GitHub Desktop.
// run sockjs server on port 9999
// use an old browser (ex: FF 3.5) which connects via polling transport
// frontend on 8888
bouncy(function (req, bounce) {
if(headers.hasOwnProperty('upgrade')) {
// check if the request for upgrade is for websocket
// else just destroy the socket
if(headers.upgrade.toLowerCase() === 'websocket') {
bounce(9999);
return;
// skip nonwebsocket + regular request
} else {
req.socket.destroy();
return;
}
}
var url = req.url.split('/').slice(0, 3).join('/'); // this is for the mount point
if(url.search('/echo/') === 0) {
var server = parseInt(url.split('/echo/')[1]); // check if request is to
// a genuine sockjs server
// and not some crappy
// iframe.html request
if(!isNaN(server)) {
bounce(9999);
return;
// skip regular request
}
}
bounce(9999);
return;
}
}).listen(8888);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment