CORS issue with demographics8.arcgis.com

2321
4
09-28-2018 03:46 PM
ToddAtkins
Occasional Contributor

In testing out the 4.9 API, I'm running into and issue around CORS with demographics8.arcgis.com. We're pulling a MapImageLayer from this domain and it's throwing a CORS error in the console. I've tried 

esriConfig.request.trustedServers.push('https://demographics8.arcgis.com');

but that didn't help. Is there something else I need to do on my end? I'd really rather not setup a proxy since it was working in 4.8 but if that's what's required, then I'll do it. I'm wondering (hoping) if there's some issue on the Esri side for this? And for what it's worth, the legend for the layer does work--just the actual map part of the service is throwing this error.

Here's the two errors it's throwing:

Access to Image at 'https://demographics8.arcgis.com/arcgis/rest/directories/arcgisoutput/USA_Demographics_and_Boundaries_2018_MapServer/x_____x8rpmfxe7ycCrgTOULj6txw..x_____x_ags_map00d241a884ec469dafb1aeebc2cb111d.png?token=<redacted>' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

and

{"error":{"name":"request:server","message":"Unable to load the resource","details":{"url":"https://demographics8.arcgis.com/arcgis/rest/directories/arcgisoutput/USA_Demographics_and_Boundaries_2018_MapServer/x_____x8rpmfxe7ycCrgTOULj6txw..x_____x_ags_map00d241a884ec469dafb1aeebc2cb111d.png?token=<redacted>","requestOptions":{"responseType":"image"},"ssl":false}}}
Tags (1)
0 Kudos
4 Replies
Noah-Sager
Esri Regular Contributor

Hi Todd, you might need to add the domain to the list of trustedServers using esriConfig.

example:

require(["esri/config"], function(esriConfig) { esriConfig.request.trustedServers.push("[<protocol>//]<hostname>.<domain>[:<port>]"); });

config | API Reference | ArcGIS API for JavaScript 4.9 

This changed was described in a recent blog post:

https://community.esri.com/community/developers/web-developers/arcgis-api-for-javascript/blog/2018/0... 

0 Kudos
ToddAtkins
Occasional Contributor

Noah, I've tried that and no dice. (as noted in my original post  )

0 Kudos
Noah-Sager
Esri Regular Contributor

Whoops! Totally missed that. My apologies. The service requires me to login, but it seems to work at 4.9 with trustedServers 

sample:

A Pen by noah 

0 Kudos
ToddAtkins
Occasional Contributor

Interesting, I'll have to investigate this some more on my side. We're using app logins for our setup here so the user doesn't have to login to AGOL to see the premium layers. I'll look into it some more and see if something is up with our token or something but that'd be odd since the error is specific to CORS. Was just weird that it worked at 4.8 and stopped at 4.9.

For now, I've just switched the layer over to a FeatureLayer and it's working fine.

0 Kudos