問題:
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'));
}
});