Session support in Now.js

前端 未结 2 511
暗喜
暗喜 2021-01-16 03:02

Now.js quotes:

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

So:

相关标签:
2条回答
  • 2021-01-16 03:49

    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.

    0 讨论(0)
  • 2021-01-16 03:52

    I managed to find a solution (CoffeeScript), for every "everyone"-request:

    self = this
    sid = decodeURIComponent(this.user.cookie['connect.sid'])
    sessionStore.get sid, (err, session) ->
        self.user.session = session
        <<more code here>>
    

    Any way to get to this.user.session directly?

    0 讨论(0)
提交回复
热议问题