I am using a simple http-server while developing a javascript app in which there are with several ajax requests to external APIs. I started the server with "http-server --cors" via CLI, but still get "No 'Access-Control-Allow-Origin' header is present on the requested resource" errors. This occurs whether or not the external API requires a user key/pre-flight, such as:
var url = "http://api.rgrta.com/";
$.ajax({
url: url,
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("api_key","d4f...3f5");
},
type: "GET",
dataType: "json"
})
.done(function(jsonData) {
console.log("*** ajax success ***");
callbackFunc();
function callbackFunc() {
console.log("callbackFunc");
}
});
I've seen solutions involving express app.js configurations. Is node/express the only way to define request headers properly? What is the best way to set up my local http-server when developing for CORS-enabled API calls?