How do I make my sessions last cross-subdomain in Node.js Express?

匿名 (未验证) 提交于 2019-12-03 02:52:02

问题:

I want http://mydomain.com to be the same as http://www.mydomain.com

And all other subdomains.

I want sessions and cookies to hold!

回答1:

Has nothing to do with Express. It's the settings on the cookie itself that matter. Set its domain to .mydomain.com and you should be fine.

EDIT: The OP wanted more details, so here are the examples from the code.

  connect.createServer(       connect.cookieParser()     , connect.session({ cookie: { domain : ".mydomain.com" }})   ); 

and

 res.cookie('remember', 1, { domain : ".mydomain.com" }); 

should work.



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