我很难理解 nodejs 中的 session ,我在同一端口上有一个子域,但我必须重新登录。
我想知道如何配置 nodejs 以共享同一个 session ,我正在使用 passportjs 来登录用户。
我试过使用redis,但是不行,我不明白。
app.use(session({
secret: "something",
domain: '.app.localhost',
store : new RedisStore({
host: '.app.localhost',
port : 9200 ,
client: redisClient
}),
cookie : {
maxAge : 604800 // one week
}
}));
到底如何让我的子域 app.localhost 与本地主机共享相同的登录 session ?
最佳答案
假设您必须使用 express-session包裹。如何挂载系统 cookes 指的是这个域。
app.use(session({
secret: "something",
// domain: '.app.localhost', <-- This Don't put into the cookie
store : new RedisStore({
host: '.app.localhost',
port : 9200 ,
client: redisClient
}),
cookie : {
maxAge : 604800 // one week
domain: 'app.localhost', //<-- This put into the cookie the domain
}
}));
关于javascript - 允许 nodejs session 转移到子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28684308/