Created
November 28, 2011 12:59
-
-
Save shripadk/1400312 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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