gpt4 book ai didi

node.js - Now.js 中的 session 支持

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

Now.js 引用:

Simply pass a connect or express http server in nowjs.initialize and this.user.session should be available.

所以:

express = require 'express'
app = module.exports = express.createServer()
connect = require 'connect'
nowjs = require 'now'
everyone = nowjs.initialize(app)

this.user 的输出是:

{ 
clientId: '353725111301231610',
cookie: { 'connect.sid': 's0meC00k1e1nF0rm4ti0n' },
session: undefined
}

知道为什么 session 未定义吗?

最佳答案

我遇到了这个问题,结果发现这是因为我在配置express之前初始化了NowJS。

app.configure(function(){
...

app.use(express.cookieParser());
app.use(express.session({ secret: "my_key", store: redisStore }));
app.use(app.router);
});

var everyone = nowjs.initialize(app); //must be defined after app.configure

需要注意的一点是,在向服务器发出请求之前, session 不会设置,因此如果服务器重置,客户端套接字将重新连接,但在浏览器刷新页面之前, session 将处于未定义状态。

关于node.js - Now.js 中的 session 支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9066834/

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