Socket IO using express session - socket.request.res undefined
sessionMiddleware()
function proposed in many sources worked fine for me:
io.use(function(socket, next) { sessionMiddleware(socket.request, socket.request.res, next);});
with web socket.io-client
<=> socket.io
node.js server until I added socket.io-client-cpp
application to the chain - server crashed on socket.io-client-cpp
connection with above error:
TypeError: argument res is required
in sessionMiddleware()
function. People suggest to remove socket.request.res
from the middleware completely:
- https://stackoverflow.com/a/29448630/630169
- https://github.com/socketio/socket.io/issues/2971#issuecomment-326084664
and replace with {}
. However think it could be changed to slightly better variant in case somebody still need and use socket.request.res
:
io.use(function(socket, next) { sessionMiddleware(socket.request, socket.request.res || {}, next);});
This works fine for me!