I know why the CORS stuff exists: to prevent Cross-Site-Scripting Attacks, but does anyone have a way of accessing the aeroapi data successfully using XMLHTTRequest. I have tried setRequestHeader but AFAIK the Access-Control-Allow-Origin token is set on the server, not the client.
const xhr = new XMLHttpRequest();
xhr.withCredentials = true;xhr.addEventListener(‘readystatechange’, function () {
if (this.readyState === this.DONE) {
// THIS IS WHERE THE SERVER REJECTS THE REQUEST
}
});xhr.open(‘GET’, ‘https://aeroapi.flightaware.com/aeroapi/flights/search?query=-latlong+“61.0+-11.0+50.0+2.0”’, true);
xhr.setRequestHeader(‘x-apikey’, ‘MY_KEY’);
Any help would be hugely appreciated.