i'm making cross domain request (client-side & server-side). in server.js i have added this code and cross domain req are working fine
function setAcceptsHeader(req, res, next) {
'use strict';
res.setHeader('Access-Control-Allow-Origin', '*');
next();enter code here
}
app.options('*', function (req, res) {
'use strict';
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type');
res.status(200).end();
});
Problem is when i added req.redirect() in server.js, im getting error XMLHttpRequest cannot load http://localhost:1214/#/about. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
app.get('/users/:email',setAcceptsHeader, function (req, res) {
User.findOne({email:req.params.email}, function (err, post) {
if(!post){
res.json({error:'item not found'});
}
else{
res.redirect('http://localhost:1214/#/about');//not working for me
}
});
I know at client side i can use window.location to route but i want this to be implemented at server side. help!!