Now.js 中的会话支持
Now.js 引用:
只需在 nowjs.initialize 中传递一个连接或快速 http 服务器, this.user.session 就应该可用。
所以:
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
}
知道为什么会话未定义吗?
Now.js quotes:
Simply pass a connect or express http server in nowjs.initialize and this.user.session should be available.
So:
express = require 'express'
app = module.exports = express.createServer()
connect = require 'connect'
nowjs = require 'now'
everyone = nowjs.initialize(app)
The output of this.user is:
{
clientId: '353725111301231610',
cookie: { 'connect.sid': 's0meC00k1e1nF0rm4ti0n' },
session: undefined
}
Any idea why session is undefined?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了这个问题,结果发现它的发生是因为我在配置 Express 之前初始化了 NowJS。
需要注意的一件事是,在向服务器发出请求之前,不会设置会话,因此如果服务器重置,客户端套接字将重新连接,但在浏览器刷新页面之前,会话将处于未定义状态。
I ran into this problem and turns out it was happening because I was initializing NowJS before configuring express.
One thing to note is that session is not set until a request is made to the server so if the server is reset, the client socket will reconnect but session will be undefined until the browser does a page refresh.
我设法为每个“每个人”请求找到一个解决方案(CoffeeScript):
有什么方法可以直接访问 this.user.session?
I managed to find a solution (CoffeeScript), for every "everyone"-request:
Any way to get to this.user.session directly?