Created
March 24, 2014 13:04
-
-
Save mashiro/9739651 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
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