迁移Express.js 2到3,具体app.dynamicHelpers()到app.locals.use? [英] Migrating Express.js 2 to 3, specifically app.dynamicHelpers() to app.locals.use?
本文介绍了迁移Express.js 2到3,具体app.dynamicHelpers()到app.locals.use?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将Express.js从版本2更新为3,并且以下对 app.dynamicHelpers({..})
的调用在V3中不再存在:
Updated Express.js from version 2 to 3, and the following call to app.dynamicHelpers({..})
broke as it is no longer present in V3:
app.dynamicHelpers({
request: function(req){
return req
},
...etc.
});
有一个迁移指南,这说明:
-
app.dynamicHelpers()
(使用中间件+ res.locals)
app.dynamicHelpers()
(use middleware + res.locals)
但是,我很失望怎么做有没有更具体的如何迁移这个例子?
But I'm stumped how to do that. Is there a more concrete example of how to migrate that?
相关SO发布: nodejs express 3.0
推荐答案
我与会话有同样的问题。用户,只需了解app.use功能需要<配置部分 IN ,而不是之前的位置。
I had the same problem with session.user and just fixed it by understanding that the app.use function needs to be IN the configure part, not where it was before.
之前:
app.configure();
app.dynamicHelpers({
user: function(req, res) {
return req.session.user;
}
});
之后:
app.configure(function(){
//...
app.use(function(req, res, next){
res.locals.user = req.session.user;
next();
});
//...
});
对于Flash,请查看 connect-flash
for Flash have a look at connect-flash
这篇关于迁移Express.js 2到3,具体app.dynamicHelpers()到app.locals.use?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文