问题:
How can I share a session with Socket.io 1.0 and Express 4.x?如何与 Socket.io 1.0 和 Express 4.x 共享会话? I use a Redis Store, but I believe it should not matter.我使用 Redis 商店,但我认为这无关紧要。 I know I have to use a middleware to look at cookies and fetch session, but don't know how.我知道我必须使用中间件来查看 cookie 和获取会话,但不知道如何。 I searched but could not find any working我搜索但找不到任何工作
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'));
}
});