我需要共享主域和所有子域之间的会话cookie。我有一个基于expressjs框架的两个服务的NodeJS:如何配置应用程序可用的子域cookie?
// 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? <---------
}));
所以我的问题是什么,我应该在blog.example.local
会话配置写入取得现有的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
})
}));
是否足够或者我可以优化呢?
所以我需要刚刚从'example.local'复制和粘贴设置'blog.example.local'? – Erik
是的,就是这样。 – yeiniel