jigar patel

jigar patel

  • NA
  • 310
  • 23.9k

It is possible redirect to other page URL in Node JS?

Apr 26 2018 8:33 AM
we are using below code in our application but not Working... 
 
res.redirect('/index.html'); - not working...
give me proper solution.
 
code : 
router.use(function (req, res, next) {
// check header or url parameters or post parameters for token
var token = req.cookies.token;
// decode token
if (token) {
// verifies secret and checks exp
jwt.verify(token, req.app.get('superSecret'), function (err, decoded) {
if (err) {
return res.json({ success: false, message: 'Failed to authenticate token.' });
// res.redirect('/index.html');
} else {
// if everything is good, save to request for use in other routes
console.log("Token matched");
//set coockie
res.cookie('token', token, { maxAge: 900000, httpOnly: true });
decoded = { ignoreExpiration: true };
req.decoded = decoded;
next();
}
});
} else {
console.log("Token not matched")
return res.redirect('./public/index.html');
}
});
 
Thanks,
Jigar Patel 
 
 

Answers (1)