我在使用connect-flash工作时遇到了一些问题,我得到的错误信息是:
'错误:req.flash()需要会话'
我已经看到这可能是因为应用程序的排序,但我不确定这是否是这种情况。
App.js:
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var flash = require('connect-flash');
var passport = require('passport');
var app = express();
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(session({secret: '{secret}', name: 'session_id', saveUninitialized: true, resave: true}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
路线等在
之下flash生成代码:
passport.authenticate('local', { failureRedirect: '/login', successRedirect: '/', failureFlash: true})
答案 0 :(得分:5)
问题在于如何渲染我的视图(使用req.flash数据)
更改此内容:
loginShow: function(req, res){
res.render('login', { message: req.flash });
}
对此:
loginShow: function(req, res){
res.render('login', { message: req.flash() });
}
修复了错误并导致connect-flash按预期运行。
答案 1 :(得分:4)
您的redis服务器正在运行吗?尝试
SELECT maker FROM
(SELECT maker, sum(cast(model1 as int)) as sum1, sum(cast(model2 as int)) as sum2 FROM
(SELECT p.maker, p.model as model1, pc.model as model2 FROM product AS p
FULL JOIN pc ON p.model = pc.model
WHERE p.type = 'PC') AS a
GROUP BY maker) b
WHERE sum1 = sum2
这解决了我的问题。