How to share sessions with Socket.IO 1.x and Express 4.x?

后端 未结 6 1054
轮回少年
轮回少年 2020-11-22 15:14

How can I share a session with Socket.io 1.0 and Express 4.x? I use a Redis Store, but I believe it should not matter. I know I have to use a middleware to look at cookies a

6条回答
  •  囚心锁ツ
    2020-11-22 15:44

    express-socket.io-session

    is a ready-made solution for your problem. Normally the session created at socket.io end has different sid than the ones created in express.js

    Before knowing that fact, when I was working through it to find the solution, I found something a bit weird. The sessions created from express.js instance were accessible at the socket.io end, but the same was not possible for the opposite. And soon I came to know that I have to work my way through managing sid to resolve that problem. But, there was already a package written to tackle such issue. It's well documented and gets the job done. Hope it helps

提交回复
热议问题