相关疑难解决方法(0)

如何与Socket.IO 1.x和Express 4.x共享会话?

如何与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)

session node.js express socket.io

82
推荐指数
3
解决办法
4万
查看次数

标签 统计

express ×1

node.js ×1

session ×1

socket.io ×1