带 www 和非 www 的快速会话 url

Express Session with www and non-www url

我目前将 mySite.com 和 www.mySite.com 解析到同一台服务器。我在会话选项中使用什么路径设置来确保我只创建一个可以在这两个 url 之间 "shared" 的会话?

app.use ( session ( {
    store : new RedisStoreSession(),
    secret: 'keyboardCat',
    cookie: { maxAge: 3.156e+10 },
    path: '/'  //this is the default - i'm not setting anything yet
} ) )

您可以在 cookie 中设置带有前导 .domain 参数以允许 所有 子域(包括 www)的 cookie :

app.use ( session ( {
  store : new RedisStoreSession(),
  secret: 'keyboardCat',
  cookie: { maxAge: 3.156e+10, domain: '.example.org' },
  path: '/'  //this is the default - i'm not setting anything yet
} ) )