I have application written in AngularJS. I want to get access to FlightAware API. I use the following code:
let Client = require('node-rest-client').Client;
let username = 'x';
let apiKey = 'y';
let fxmlUrl = 'https://flightxml.flightaware.com/json/FlightXML3/'
let client_options = {
user: username,
password: apiKey
}
let client = new Client(client_options);
client.registerMethod('findFlights', fxmlUrl + 'FindFlight', 'GET');
client.registerMethod('weatherConditions', fxmlUrl + 'WeatherConditions', 'GET');
let findFlightArgs = {
parameters: {
origin: 'KIAH',
destination: 'KJFK',
type: 'nonstop'
}
}
let weatherConditionsArgs = {
parameters: {
airport_code: 'KHOU'
}
}
client.methods.weatherConditions(weatherConditionsArgs, function (data, response) {
console.log('Current conditions at Hobby Airport: %j', data.WeatherConditionsResult.conditions[0]);
})
When I execute it in nodeJS it works but in my AngularJS app I get an error:
Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.
I found some information that this error is connected with CORS but the server side is the same regardless I use AngularJS or NodeJS in order to run the code. How can I execute it without an error in AngularJS?
Accept: application/xml?