Answer the question
In order to leave comments, you need to log in
How to save session declared in POST route?
The session only works in the route within which it was declared.
I use Express-session, everything works fine in GET routes.
Cookie-Parser has the same problem.
router.post('/new/', (req,res,next) => {
const data = {id: req.body.id, name: req.body.name}
req.session.cart.newItem = data
req.session.save()
})
Answer the question
In order to leave comments, you need to log in
Try to return the response in the request handler and everything will be fine. You in your implementation 504 Gateway Timeout do.
router.post('/new/', (req,res,next) => {
const data = {id: req.body.id, name: req.body.name};
req.session.cart.newItem = data;
res.status(200).send(true); // к примеру
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question