I am using node express 4.0 to implement the function of checking the message code. I use a session to store the msg code I pass. I installed the session middleware as dos said:
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(cookieParser());
app.use(session({secret:'ssssss'}));
app.use(express.static(path.join(__dirname, 'public')));
app.use('/uploads', express.static(path.join(__dirname, 'uploads/temp')));
but when I use the post method, I get the msg code, I found that the session was not successfully established.
Like this code below:
router.post('/msgCode', function(req, res) {
req.session.test = 'test';
}
when i send this router i found that req.session.testis undefined.
then I try this on another router:
router.get('/sendMsgTest', function(req, res) {
req.session.test = 'test';
res.json({
status:0
})
}
Every time I request sendMsgTest, I can receive req.session.test. And when I request another method get, I can get the value req.session.testsuccessfully.
So why is my mail method not working?