如何与Socket共享会话.io 1.0和Express 4.十、我用的是Redisstore ,但我相信这不重要.我知道我必须使用中间件来查看cookies和获取会话,但不知道如何使用.我搜索了一下,但没有找到任何工作
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'));
}
});