I'm trying to access a node route through angular $http
using the cors
module. I've tried a simple
app.use(cors());
but still get the error. And I've tried adding from the cors documentation a whitelist of URLs
var corsOptions = {
origin: function(origin, callback){
var originIsWhitelisted = whitelist.indexOf(origin) !== -1;
callback(null, originIsWhitelisted);
}
};
app.get('/someroute/:someparam/', cors(corsOptions), function(req, res, next){
mymodule.getData(req.params.someparam, function(err, data){
if (err){
console.log('error with route', err);
}else{
res.json({result: data});
}
});
});
But I'm still getting the error
XMLHttpRequest cannot load localhost:8888/someroute/undefined. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
I thought that using the cors module was meant to avoid this problem. How can I solve?