如何配置应用程序可用的子域cookie?

Eri*_*rik 9 cookies subdomain node.js express

我需要在主域和所有子域之间共享会话cookie.我有两个基于expressjs框架的nodejs服务:

// example.local

    ...
    app.use(session({
       cookie: {
          domain: "example.local"
       }
       , key: 'sid'
       , secret: '[my secret]'
       , saveUninitialized: true
       , resave: true
       , store: new RedisStore({
          host: 'localhost',
          port: 6379
       })
    })); 

// blog.example.local

    ...
    app.use(session({
       // what should I write here? <---------
    })); 
Run Code Online (Sandbox Code Playgroud)

所以我的问题是我应该在会话配置中写什么blog.example.local才能访问现有的cookie example.local

编辑:正如@yeiniel建议的那样,我应该使用相同的配置,blog.example.local如下所示:

// blog.example.local

    ...
    app.use(session({
       cookie: {
          domain: "example.local"
       }
       , key: 'sid'
       , secret: '[my secret]'
       , saveUninitialized: true
       , resave: true
       , store: new RedisStore({
          host: 'localhost',
          port: 6379
       })
    })); 
Run Code Online (Sandbox Code Playgroud)

是否足够或我可以优化它?

yei*_*iel 6

基本上你需要两件事:在所有服务器上使用相同的设置(不仅仅是cookie设置,而是包括商店的所有会话设置),并确保cookie域配置指向站点之间的公共域.