是否有支持完全由客户端管理的会话的框架?换句话说,不是仅将已签名的pid存储在cookie中(如Express所做的那样),而是存储所有上下文......这样您就可以跨群集管理状态而无需持久化。
答案 0 :(得分:1)
有快速中间件支持这个:
https://github.com/expressjs/cookie-session
cookieSession()
提供基于cookie的会话,并填充req.session。此中间件采用以下选项:
中间件:
var cookieSession = require('cookie-session')
...
app.use(cookieSession({
name: "my_session_cookie",
secret: "dont_tell_anybody_the_secret_and_change_it_often",
options: { ... }
));
app.use((req, res, next) => {
// set options on req.session before your response goes out
req.session.viewCount = (req.session.viewCount || 0) + 1;
res.end(`You viewed the page ${req.session.viewCount} times.`);
});
要清除cookie,只需在响应之前将会话分配为null:
req.session = null