Recently, I’m getting CORS errors on r = d3.json("https://data.rivm.nl/covid-19/COVID-19_reproductiegetal.json"). I haven’t changed the notebook and I can access the data by just browsing the URL.
Any clues? Is it Observable runtime? Safari? macOS? iPadOS? Firefox? Chrome? Me?
New CORS security on the server and/or browser? Being able to reach it directly would be a single-origin request, I think. Solutions = your own proxy or sneaking a ride:
The issue is you have to manually allow-list API access to browsers through headers. If they do not do that the browser will not connect. So either 1. they add the headers, or 2. you access the data through a proxy that does have the right headers
In the example script, they have a line like this: response.headers.set("Access-Control-Allow-Origin", url.origin)
To make it work regardless of how how requests are sent, change it to: response.headers.set("Access-Control-Allow-Origin", “*”)
You then get a URL for the worker, and need to add your desired API endpoint as URL encoded apiurl query param: https://cloudflare-worker-url.dev?apiurl=${escape(‘https://your-api.com’)}