如何在Node.js Express中使我的会话最后一个跨子域? [英] How do I make my sessions last cross-subdomain in Node.js Express?

查看:92
本文介绍了如何在Node.js Express中使我的会话最后一个跨子域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望 http://mydomain.com http://www.mydomain.com

所有其他子域名。

我想要会话和cookie保持!

I want sessions and cookies to hold!

推荐答案

与Express无关。这是Cookie本身的设置很重要。将其域设置为 .mydomain.com ,您应该可以。

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.

编辑 :OP想要更多的细节,所以这里是代码中的例子。

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


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



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


应该工作。

这篇关于如何在Node.js Express中使我的会话最后一个跨子域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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