简体   繁体   中英

Express Session with www and non-www url

I currently resolve mySite.com and www.mySite.com to the same server. What path setting do I use in the session options to ensure I'm only creating a single session that can be "shared" between those two urls?

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

You can set the domain parameter in cookie with a leading . to allow the cookie for all subdomains (including www):

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
} ) )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM