NowJS cookie field in this.user is empty

假装没事ソ 提交于 2019-12-11 15:23:03

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/12555626/nowjs-cookie-field-in-this-user-is-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!