Handling CORS issue while using GeoJSON layer URL

738
4
07-18-2019 06:08 AM
GeorgeAbraham1
New Contributor II

To test an application, I created a sample GeoJSON on my AWS and passing its URL to the GeoJSON Layer JS API to access it - however I am facing CORS issue.

For now I am able to bypass it with disabling Chrome security, however, I wanted to know if there is any means to pass appropriate Request headers to fix this for final.

I tried:

var options = {
query: {
f: "json"
},
responseType: "json",
mode: "no-cors"
};

and also

var options = {
query: {
f: "json"
},
responseType: "json",
headers: {
"Access-Control-Allow-Headers": "*"
}
};

when I am using require(["esri/request"] but to no success - its still throwing the same error. What am I missing here?

Tags (1)
0 Kudos
4 Replies
GeorgeAbraham1
New Contributor II

I even tried with "Access-Control-Allow-Origin": "*" but then it gives the error "Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response."

0 Kudos
GeorgeAbraham1
New Contributor II

Robert Scheitlin, GISP‌ - Anything you could help me with?

0 Kudos
Noah-Sager
Esri Regular Contributor

Couple ideas to try:

1) esriConfig.request.trustedServers

https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#request

Indicates whether cross origin requests made to the associated server should include credentials such as cookies and authorization headers.

2) CORS guide page

https://developers.arcgis.com/javascript/latest/guide/cors/index.html

3) Try using a proxy

https://developers.arcgis.com/javascript/latest/guide/proxies/#example%3A-server-is-not-enabled-for-...

GeorgeAbraham1
New Contributor II

Hi Noah,

I had gone through these links but was looking more for a sample application - anyways for now we managed to enable the service as CORS enabled, so issue resolved.