Hi Rhys,
I am also trying to pass api-key in header using esriConfig.request.interceptors as well as esriConfig.request.trustedServers, however, it doesn't return the geojson results as I am able to extract through postman. Any crue what is causing CORS error through this request method?
esriConfig.request.trustedServers.push(this.base_url);
esriConfig.request.interceptors.push({
urls: geojson_url,
before: function (params: any) {
params.requestOptions.headers = {
'x-api-key': this.x_api_key,
'Access-Control-Allow-Origin': this.base_url,
};
},
after: function(response) {
if (!response.ssl) {
response.ssl = true;
}
const geojsonLayer = new GeoJSONLayer({
title: 'Forecast Kind',
url: response.data,
popupTemplate: template_forecast_kind,
visible: false,
outFields:["*"]
});
},
headers: {
'x-api-key': this.x_api_key,
'Access-Control-Allow-Origin': '*',
},
});
The error shows:
Access to fetch at 'https://.....com/sites/current_forecast_status' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Thanks,
Shingo
Shingo Ikeda
Geospatial Data Scientist/Developer - Geographical Information Platform
Global Power Generation - Digital Satellite USA and Canada