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 ページの指示に従いました。私は何が欠けていますか?