gpt4 book ai didi

node.js - 使用express-session和express-socket.io-session NodeJs时出错

转载 作者:太空宇宙 更新时间:2023-11-03 22:09:37 25 4
gpt4 key购买 nike

我正在使用nodejsexpress-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);
});

我希望我已经清楚地了解了我的问题。谢谢

最佳答案

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

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));

关于node.js - 使用express-session和express-socket.io-session NodeJs时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46415201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com