✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

Error connecting Sanity CMS to a site deployed on Vercel, seeking help with CORS configuration and API endpoint.

9 replies
Last updated: Mar 14, 2024
Hi all, I've recently started working with the sanity cms, and I'm trying to connect it to a site that I've deployed on vercel. I keep getting the following error
GET <http://localhost:3000//api/experience> net::ERR_CONNECTION_REFUSED
. I've checked all my environment variables as well and made sure that my
file has the required keys as follows:
#SANITY_API_VERSION=2021-03-25 // The API version you want to target 
Has anyone encountered this before? If so I'd really appreciate some help with this. I really don't know where I screwed up. Thanks a lot in advance!
Mar 13, 2024, 11:16 AM
👋 Have you added that port to your CORS origins in sanity.io/manage ?
Mar 13, 2024, 4:43 PM
I added the whole url for the site that vercel generated. Can you share an example of what the correct CORS value is supposed to look like please? 😅
Mar 13, 2024, 4:46 PM
Mar 13, 2024, 4:47 PM
Oh, also I just noticed the double
. Is that intended?
Mar 13, 2024, 4:47 PM
So I added localhost:3000 into the cors origin.
Also the // isnt intended. So I used postman to check the vercel url ‘testurl/api/experience’ and it returns data. But for some reason when I check the console of the deployed site, it gives me that error
Mar 13, 2024, 4:49 PM
Would it help if I set a base url value in the env.local file?
Mar 13, 2024, 4:58 PM
user M
there was a typo in some of the url strings that used the baseurl environment variable. Its all good, and the site is deployed too!
Mar 14, 2024, 3:11 PM
Mar 14, 2024, 3:11 PM
Glad you got it sorted out!
Mar 14, 2024, 3:18 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?