I have generated a client side app with swagger codegen for a specific API, the javascript version. Initialized it with npm etc. etc. everything claps.
However when i try to send a get request with the generated api from my localhost to http://81.2.241.234:8080/species i get the following error:
Error: Request has been terminated Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc. at Request.crossDomainError (bundle.js:2967) at XMLHttpRequest.xhr.onreadystatechange (bundle.js:3049)
The mentioned headers are present on the servers response if i call the url from chrome.
Some code for easier understanding:
var speciesApiInstance = new index.SpeciesServiceApi();
var opts = {
'start': 0, // Number | start position
'count': 10, // Number | count
'orderfield': "name", // String | order by
'orderdirection': "ASC" // String | order direction
};
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
speciesApiInstance.getSpecies(opts, callback);
What am I doing wrong? Couldn't find an answer in the docs.
Solution: I was using HTTPS connection, the mentioned IP connects with http only, thus the preflight request failed. Modified the connection url to call the API with http and it works properly.