使用NodeJS和ExpressJS为domain而不是subDomain设置cookie [英] Set cookie for domain instead of subDomain using NodeJS and ExpressJS
本文介绍了使用NodeJS和ExpressJS为domain而不是subDomain设置cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在使用expressjs和mongostore进行会话管理。以下是在expressjs中配置商店的代码,
app.configure(function(){
app.use express.session({
secret:conf.secret,
maxAge:new Date(Date.now()+ 3600000),
cookie:{path:'/'},
store:new MongoStore(conf.db)
}));
});
我在上面的代码中提到了cookie路径。但它设置cookie在sub.domain.com而不是.domain.com。如何实现这一点?
b p $ p>
app.use(express.session({
secret:conf.secret,
cookie:{domain:'。yourdomain.com'},
store:new MongoStore(conf.sessiondb)
}));
I have been using expressjs and mongostore for session management. Following is the code to configure store in expressjs,
app.configure(function(){
app.use(express.session({
secret: conf.secret,
maxAge: new Date(Date.now() + 3600000),
cookie: { path: '/' },
store: new MongoStore(conf.db)
}));
});
I had mentioned the cookie path in the above code. But it sets the cookie in sub.domain.com instead of .domain.com. How do i achieve this?
解决方案
configure it like this:
app.use(express.session({
secret: conf.secret,
cookie: { domain:'.yourdomain.com'},
store: new MongoStore(conf.sessiondb)
}));
这篇关于使用NodeJS和ExpressJS为domain而不是subDomain设置cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文