expressnowjs-sockets

NowJS cookie field in this.user is empty


According to these: https://gist.github.com/2266544, Session support in Now.js.

This code should return the NowJS clientId, cookie and session:

nowjs.on('connect', function() { console.log(this.user); })

However, what I got was:

{ clientId: 'something', cookie: { } }

The cookie field is empty. There is no session entry (which I read is an official problem).

Additional Information

I am also using ExpressJS, PassportJS, Mongoose, session-mongoose. I initialized NowJS after configuring Express.

Question

Why is my cookie field empty and how can I get it populated?


Solution

  • After many hours of frustration I discovered that the cookie was not being sent because I was listening to port 3000, which was considered a cross domain request. The port that is being listened to has to be the http server that set the cookie.

    I am using Dreamhost, which has Apache listening to port 80 and we're not allowed to unbind it, or bind to port 80. But I was able to resolve this by listening to port 8080.

    The cookie was successfully sent when I set it to listen to port 8080.

    Edit

    This only worked for a short time. Not sure why. Cookies stopped being sent after a while.

    Edit 2

    This worked again after I set up a proxy forwarding 80 to 8080 (google for "dreamhost proxy"). Essentially putting Apache in front of Node.