Session.js中的会话支持 [英] Session support in Now.js

查看:152
本文介绍了Session.js中的会话支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Now.js引号:


只需在nowjs.initialize中传递一个连接或表达http服务器,而this.user.session应该是

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的输出是:

The output of this.user is:

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

任何想法为什么会话未定义?

Any idea why session is undefined?

推荐答案

我遇到这个问题,原来是因为我在配置express之前初始化NowJS。

I ran into this problem and turns out it was happening because I was initializing NowJS before configuring express.

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

需要注意的一点是,会话没有设置,直到要求服务器,所以如果服务器被重置,客户端套接字将重新连接,但会话将被定义,直到浏览器刷新页面。

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.

这篇关于Session.js中的会话支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆