我使用client-sessions而不是express sessions。如何获取会话数据?会话存储在客户端,而不是服务器上。
我使用client-session模块https://github.com/mozilla/node-client-sessions
我使用client-sessions而不是express sessions。如何获取会话数据?会话存储在客户端,而不是服务器上。
我使用client-session模块https://github.com/mozilla/node-client-sessions
handshakeData.cookie = cookie.parse(handshakeData.headers.cookie);
你需要解码cookie,我使用了client-session模块的原始函数。
var clientSessions = require('./node_modules/client-sessions/lib/client-sessions')
var opts = {
cookieName: 'yourSessionName'
, secret: 'secret'
}
var decoded = clientSessions.util.decode(opts, handshakeData.cookie['yourSessionName'])
decoded对象保存了您的会话数据
如果你想在客户端获取会话数据,你只需使用模块内置的功能。如果你需要在服务器上获取它,则可以在客户端获取信息,并使用socket.io进行发射,例如socket.emit('sendSocketData', dataToSend);