Reputation: 95
I have an angular app and node backend and all the request is properly working but when I try to use a get request and inside that I am redirecting the request then 'CORS preflight channel did not succeed' this error is happening...when I am trying in postman I am getting my desire result...but not in browser
router.get('/monthdata/:month' , jwtHelper.verifyJwtToken , ctrlData.getMonthData);
router.post('/monthdata' , jwtHelper.verifyJwtToken , ctrlData.postMonthData);
module.exports.postMonthData = (req , res , next) =>{
let month = req.body.month;
//console.log(`/api/monthdata/${month}` );
res.redirect(`/api/monthdata/${month}`);
}
module.exports.getMonthData = (req , res , next) =>{
Data.find({
_creator : req._id , month : req.params.month
} , (err , data)=>{
if(!data)
return res.status(400).json({status : false , message : 'Data notfound'})
else
return res.status(200).json({status: true , data})
});
}
Upvotes: 0
Views: 386
Reputation: 5539
In your node backend, add this above all the routes:
app.use(cors({origin: true, credentials: true}));
One request that is failing would have Authorization
in the header. Including credentials: true
will solve the issue.
Upvotes: 1