I am currently trying to implement session management using express 4.x and socket io 1.4, referencing this answer. The problem is that the second argument to the express session function is the res (response) object which is returning 'undefined' in my route. Is this question outdated or am I doing something wrong?
var http = require('http');
var session = require('express-session')(
{
saveUninitialized : false,
resave:false,
secret:'secretstuff',
cookie : {
path : '/'
}
}
);
var express = require('express');
var app = express();
app.use(session)
var http_server = http.createServer(app);
var io = require('./sockets')(http_server,session);
here is my sockets.js
var Server = require('socket.io');
module.exports = function(http_server, session)
{
var io = new Server(http_server);
io.use(function(socket,next){
//socket.request.res === undefined
session(socket.request, socket.request.res,next);
})
}
which is where I get
Uncaught TypeError: argument res is required
sessionMiddleware()
function proposed in many sources worked fine for me:with web
socket.io-client
<=>socket.io
node.js server until I addedsocket.io-client-cpp
application to the chain - server crashed onsocket.io-client-cpp
connection with above error:in
sessionMiddleware()
function. People suggest to removesocket.request.res
from the middleware completely:and replace with
{}
. However think it could be changed to slightly better variant in case somebody still need and usesocket.request.res
:This works fine for me!