Now.js 引用:
只需在 nowjs.initialize 中传递一个连接或快速 http 服务器, this.user.session 就应该可用。
So:
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
}
知道为什么会话未定义吗?
我遇到了这个问题,结果发现这是因为我在配置 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
需要注意的一件事是,在向服务器发出请求之前,不会设置会话,因此如果服务器重置,客户端套接字将重新连接,但在浏览器刷新页面之前,会话将处于未定义状态。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)