I am trying to make cross domain call from angular.js module to nodejs + express server, and I am getting unauthorized error, or headers errors: I followed the Cors configuration and still I am having an issue.
Angular.js code:
methods.getWelcomeApps = function (onSuccess, onError) {
function makeBasicAuth(user, password) {
var tok = user + ':' + password;
var hash = btoa(tok); // Base64 encoding
return "Basic " + hash;
}
var auth = makeBasicAuth(config.API.AppsList.username, config.API.AppsList.password);
$http.defaults.useXDomain = true;
$http({method: 'GET', url: config.API.AppsList.url, headers: {'Authorization': auth}})
.success(onSuccess)
.error(onError);
};
return methods;
});
And the node.js code:
allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'X-Requested-With');
res.header('Access-Control-Allow-Headers', 'Content-Type');
if (req.method === 'OPTIONS') {
return res.send(200);
}
return next();
};
Do I miss something?
thx.