如何与Socket.io 1.0和Express 4.x共享会话?我使用Redis商店,但我认为这无关紧要.我知道我必须使用中间件来查看cookie和获取会话,但不知道如何.我搜索但找不到任何工作
var RedisStore = connectRedis(expressSession);
var session = expressSession({
store: new RedisStore({
client: redisClient
}),
secret: mysecret,
saveUninitialized: true,
resave: true
});
app.use(session);
io.use(function(socket, next) {
var handshake = socket.handshake;
if (handshake.headers.cookie) {
var str = handshake.headers.cookie;
next();
} else {
next(new Error('Missing Cookies'));
}
});
Run Code Online (Sandbox Code Playgroud)