Skip to content

Instantly share code, notes, and snippets.

@mashiro
Created March 24, 2014 13:04
Show Gist options
  • Save mashiro/9739651 to your computer and use it in GitHub Desktop.
Save mashiro/9739651 to your computer and use it in GitHub Desktop.
function koaSession() {
return function(socket, next) {
var req = socket.request;
var res = new http.ServerResponse(req);
var ctx = app.createContext(req, res);
var gen = function *() { next(); };
var sess = session();
this.ctx = ctx;
sess.call(ctx, gen()).next();
};
}
io.use(koaSession());
io.use(function(socket, next) {
console.log(this.ctx.session);
next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment