Reputation: 5230
I generated a new sails.js app and created a test API as follows.
module.exports = {
test:function (req, res) {
return res.ok({success: true});
},
}
The sails
app is hosted in a standalone local machine with at 192.168.3.208:1337
.
My CORS
config is as follows.
module.exports.cors = {
origin: '*',
credentials: true,
};
When I make a simple AJAX
call from my local machine (192.168.3.210
) to the API,
$.ajax({
type: 'GET',
url: 'http://192.168.3.208:1337/api/test',
dataType: 'json',
success: function(data) {
console.log(data);
},
failure: function(data) {
console.log(data);
}
});
I get the following error
Failed to load http://192.168.3.208:1337/api/test: The 'Access-Control-Allow-Origin' header contains the invalid value ''. Origin 'http://localhost' is therefore not allowed access.
The html page is hosted with Apache at port 80.
What am I missing here?
Upvotes: 0
Views: 3878
Reputation: 5230
This solved the problem
module.exports.cors = {
origin: '*', // Required whitelist
credentials: true,
headers: ['Authorization', 'content-type', 'user-agent']
};
Upvotes: 1