使用express-session和express-socket.io-session NodeJ时出错

时间:2017-09-25 22:37:48

标签: node.js sockets session express express-session

我正在使用nodejs express-session和express-socket.io-session,问题是当我运行我的server.js时,有一些错误:

express-session deprecated undefined resave option; provide resave option node_modules\express-socket.io-session\index.js:66:7
express-session deprecated req.secret; provide secret option node_modules\express-socket.io-session\index.js:66:7
express-session deprecated undefined saveUninitialized option; provide saveUninitialized option node_modules\express-socket.io-session\index.js:66:7

以下是代码:

var express = require('express');
var session = require('express-session');
var io = require('socket.io').listen(http);
var sharedsession = require("express-socket.io-session");
var app = express();

app.use(session({
   secret: 'ssshhhhh',
   resave: true,
   saveUninitialized: true
}));

io.use(sharedsession(session, {
   resave: true,
   secret: 'ssshhhhh',
   saveUninitialized: true
}));

io.sockets.on('connection', function(socket){
   console.log(socket.handshake.session);
});

我希望我能清楚我的问题。感谢

1 个答案:

答案 0 :(得分:1)

您的设置看起来不正确,您希望以可以在express和socket.io之间共享的方式定义会话,例如。

const session = require('express-session')({  
   secret: 'ssshhhhh',
   resave: true,
   saveUninitialized: true
});
const sharedsession = require('express-socket.io-session');
...
app.use(session);
io.use(sharedsession(session));