Troubleshooting CORS configuration for Sanity with custom domains

8 replies
Last updated: Sep 28, 2021
Hello, I have a question about configuring CORS origins. I have a frontend site hosted on netlify, and early on in development I configured my sanity instance to allow the randomly generated domain that netlify generated for the site to connect to the project. Now I have also added a custom domain that I bought on namecheap and setup that domain to point to the netlify site. The problem is that now when I try to whitelist my new custom domain on the sanity CORS page, it doesn’t appear to have any effect, and all my requests are blocked. Can you recommend that I try anything to resolve this problem? Thanks!
Sep 28, 2021, 8:12 PM
Hey User! What's the error you get in the console when this happens?
Sep 28, 2021, 8:23 PM
Hi User! This is what I see
No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
Sep 28, 2021, 8:26 PM
Hi User! This is what I see
No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
Sep 28, 2021, 8:26 PM
/#/timeline/National%20Timeline:1 Access to XMLHttpRequest at ‘https://hl710q4f.api.sanity.io/v1/data/query/production?query=*%5B_type%20%3D%3D%20%22post%22%20%26%26%20%24keyword%20in%20categories%5B%5D-%3Etitle%5D%20%7C%20order(date)%7B%0A%20%20title%2Cbody%2CfullBody%2Ccitations%2Cdate%2CmainImage%2C%20categories%0A%7D&%24keyword=%22National%20Timeline%22 ’ from origin ‘https://www.landgrabct.org ’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
Sep 28, 2021, 8:28 PM
I noticed of course I can create a wildcard entry and it works, but I guess that is not ideal
Sep 28, 2021, 8:30 PM
I noticed of course I can create a wildcard entry and it works, but I guess that is not ideal
Sep 28, 2021, 8:30 PM
Hmm, is it possible that you've added
http://
instead of
https://
? Or maybe something along those lines?
Sep 28, 2021, 8:32 PM
OH! I think I got it. I ended up setting up two records, one with www and one without. I was trying to setup something with wildcards like this but it did not work. I guess maybe I misunderstood how * could be used.
https://*<http://landgrabct.org|landgrabct.org>*
Sep 28, 2021, 8:35 PM

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?