如何在Node.js Express中使我的会话成为最后一个跨子域?

时间:2023-01-13 12:12:42

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

我希望http://mydomain.com与http://www.mydomain.com相同

And all other subdomains.

和所有其他子域名。

I want sessions and cookies to hold!

我希望会话和cookie能够召开!

1 个解决方案

#1


12  

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.

与Express无关。它本身就是cookie本身的设置。将其域名设置为.mydomain.com,您应该没问题。

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

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

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

and

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

should work.

应该管用。

#1


12  

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.

与Express无关。它本身就是cookie本身的设置。将其域名设置为.mydomain.com,您应该没问题。

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

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

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

and

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

should work.

应该管用。