我在路线上遇到了问题(注册):
TypeError: req.flash is not a function
at /Users/laurent/Projects/perso/express-live-stream/server/routes/register.js:11:32
在 app.js 中设置
const Session = require('express-session');
const flash = require('connect-flash');
app.use(require('cookie-parser')());
app.use(Session({
store: new FileStore({
path : './server/sessions'
}),
secret: config.server.secret,
cookie: {maxAge: Date().now + (60 * 1000 * 30) } ,
resave: false,
saveUninitialized: false
}));
app.use(flash());
路由器 (routes/register.js)
const express = require('express'),
router = express.Router(),
passport = require('passport');
router.get('/',
require('connect-ensure-login').ensureLoggedOut(),
(req, res) => {
res.render('register', {
user : null,
errors : {
username : req.flash('username'), <== problem here (line 11)
email : req.flash('email')
}
});
});
看来我的设置没问题,因为闪存消息存储在会话中。我之前在谷歌上查过,但没有找到任何东西
谢谢
洛朗