express.js路由中的全局会话变量? [英] Global session variable in express.js route?
本文介绍了express.js路由中的全局会话变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在express.js路由中设置会话时
when i set a session in express.js route like
app.get('/', function(req, res() {
req.session.foo = 'bar';
});
我无法在其他路由中访问它(未定义).这可能吗?我必须考虑一种特殊的配置吗?
i can't access it (undefined) in other routes. is this possible? is there a special configuration i have to consider?
谢谢!
推荐答案
我实际上只是通过设置如下会话来解决它:
i actually solved it by just setting the sessions like this:
global.session.email = JSON.parse(chunk).email;
由此,会话变量是全局的!
through this, the session variables are global!
已解决!
这篇关于express.js路由中的全局会话变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文