Skip to content

Instantly share code, notes, and snippets.

@3rd-Eden
Created February 27, 2013 11:09
Show Gist options
  • Save 3rd-Eden/5047169 to your computer and use it in GitHub Desktop.
Save 3rd-Eden/5047169 to your computer and use it in GitHub Desktop.
this.io = this.engine = new Engine.Server();
//
// Handle WebSocket server upgrades, again, check if it's a valid request.
// BE-AWARE HERE BE DEMONS AND MONKEY PATCHES.
// - There is no way to re-using the middleware that is specified in
//
server.on('upgrade', function upgrade(req, socket, head) {
req.originalUrl = req.url; // connect compatibility
common.async.series([
self.cookieParser.bind(self.cookieParser, req, socket)
, self.sessionStore.bind(self.sessionStore, req, socket)
], function finished() {
if (!req.session.loggedIn) return socket.end();
self.engine.handleUpgrade(req, socket, head);
});
});
// Add the requestHandle to the connect/express middleware
connect.use(function (req, res, next) {
self.engine.handleRequest(req, res);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment