Esri / cedar

JavaScript Charts for ArcGIS
https://esri.github.io/cedar
256 stars 238 forks source link

CORS Issue? #264

Open pwild opened 7 years ago

pwild commented 7 years ago

Just trying to get started with the bar chart sample and get the No 'Access-Control-Allow-Origin' CORS error.

No chart displays, but I can browse to the response?

Thoughts?

jgravois commented 7 years ago

hi @pwild!

the same browser cross origin rules apply to cedar that apply everywhere else, but you have several different options...

  1. the first (and best option) is to enable CORS on the webserver that hosts the GIS services you're attempting to chart.
  2. if that's not possible, you could also run a proxy alongside your own web application
var chart = new Cedar({
    "type":"scatter",
    "dataset":{
      // another public service that doesn't support CORS
      "url":"/proxy/proxy.ashx?http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSPetro/MapServer/0"
    }
  });

if you'd like to learn more about the how's and why's of proxies, i've always liked the article below: https://developers.arcgis.com/javascript/3/jshelp/ags_proxy.html


for the maintainers,

since d3.xhr() always makes a CORS request, a fallback JSONP GET request would be pretty beneficial to users who aren't able to modernize the web servers they are charting content from.

http://stackoverflow.com/questions/10627703/d3-json-d3-xhr-and-cross-domain-problems

benstoltz commented 7 years ago

@jgravois Tots regarding d3.xhr(). In fact with v1 we probably overhaul how we do requests in general.