gpt4 book ai didi

node.js - 类型错误 : Object # has no method 'flash'

转载 作者:搜寻专家 更新时间:2023-10-31 22:26:01 25 4
gpt4 key购买 nike

我在使用 Node.js 和 Express 时收到以下错误。这是我的版本:

Node : v0.8.8
Express: 3.0.0rc3

尝试访问页面时出现以下错误:

TypeError: Object #<IncomingMessage> has no method 'flash'
at routes (/Users/nblavoie/Desktop/HotPie/HotPie/apps/authentication/routes.js:23:8)

我试图删除 app.use(app.router);从 app.js 没有成功。这是导致错误的代码。请参阅 req.flash 行。

app.post('/sessions', function(req, res)
{
if(req.body.user == 'piechief'
&& req.body.password == '12345')
{
req.session.currentUser = req.body.user;
req.flash('info', "You're logged in as #{req.session.currentUser}");
res.redirect("/login");
return;
}
else
{
req.flash('error', "Those credentials were incorrect. Try again.");
res.redirect("/login");
return;
}
});

这是我的 app.js 中有趣的部分:

var app = express();

app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.session({
secret: "DBBD6BE563419EDB0E5CBD228E603D4AD232CE05434B4FA95C6908B64EA515C3",
store: new RedisStore({
host: "127.0.0.1",
port: "6379",
db: "mydb"
})
}));
app.use(app.router);
app.use(express.static(path.join(__dirname, '/public')));
});

有什么想法吗?我对 Express'flash documentation 很感兴趣而且我看不出我做错了什么。

最佳答案

req.flash 已经是 removed as of 3.0 :

  • req.flash() (just use sessions: req.session.messages = ['foo'] or similar)
  • connect-flash can be used as middleware to provide req.flash()

关于node.js - 类型错误 : Object #<IncomingMessage> has no method 'flash' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12121887/

25 4 0
文章推荐: html - 如何使
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com