我正在尝试在我的express3应用程序中使用connect-flash。
我成功安装了这个包:
$ npm install connect-flash我把它包括进来了:
var flash = require('connect-flash');设置中间件:
app.use(function(req, res, next) {
res.locals.message = req.flash();
next();
});
app.use(flash());并使用它:
app.get('/admin', function(req, res) {
if(loggedIn === true) {
res.redirect('/admin/books');
}
else {
res.render('login', {message: req.flash('error') });
}
});
app.post('/admin', function(req, res) {
if((adminAccount.username === getCrypted(req.body.username)) &&
(adminAccount.password === getCrypted(req.body.password))) {
loggedIn = true;
res.redirect('/admin/books');
}
else {
req.flash('error', 'Woops, looks like that username and password are incorrect.');
res.redirect('/admin');
}
});然而,我得到了:TypeError: Object #<IncomingMessage> has no method 'flash'。我按照它的github页面上的说明操作。我遗漏了什么?
发布于 2012-11-07 09:06:15
颠倒顺序:
app.use(flash());
app.use(function(req, res, next) {
res.locals.message = req.flash();
next();
});https://stackoverflow.com/questions/13261550
复制相似问题