CORS for your Sapper and Sanity

If you've setup a Sapper site with Sanity, then you might have run into some additional configuration that isn't obvious, especially to a front-end rookie.

Everything is setup with content and your custom domain, but for some reason the first time your site fetches the content, you get a 500 error message on the page:

Ok, let's look at the console:

Ah man, you know why I'm here!

Ok, there must be something I missed!

Let's check the code...hmm, not sure about that.

Let's take a look at the Sanity project. Hmm, Settings > API. CORS Origins!

Take a look at the requesting domain that's causing the CORS errors in the console and add it to this list of API approved domains. Fixed!

I first assumed that adding a custom domain to a project would take care of CORS, but I was wrong - made an ass out of me.

Hope that helps someone!

Jeffrey Fate