Issue with deploying a Next.js app to Vercel and configuring CORS for Sanity.io

19 replies
Last updated: Nov 29, 2022
Hi, I’ve just tried to deploy my next app to vercel but i get an error. Before i was having issues with projectId not being found but i think i solved that, if i do vercel build, vercel deploy --prebuilt i get a preview site that works fine, when i just use vercel in the terminal i get this error.
Nov 29, 2022, 4:53 PM
Your issue looks to be with this line. You're likely not providing an absolute string or URL instance in your middleware.
Nov 29, 2022, 6:12 PM
hi thanks for your response, i thought it made sense to look into geInfo
Nov 29, 2022, 6:53 PM
getPageInfo*
Nov 29, 2022, 6:53 PM
im not sure i understand what it talks about in reference to the url, this is my first time makinga nextjs sanity app
Nov 29, 2022, 6:55 PM
Hmm, that doesn't look like a string/url issue then! Is it possible that your queries to sanity are failing? How is your client configured? Have you added Vercel to your CORS origins?
Nov 29, 2022, 7:02 PM
my sanity requests seem to be working fine when i dont try to deploy using vercel command ie if i use vercel deploy --prebuilt my site runs fine with all the content from sanity. The way i have my app is after i built all of my next app i integrated sanity into it ad at the end deployed to vercel, i havent deployed sanity studio yet as it seems to be running fine off the normal link. What would i need to do to add vercel to CORS
Nov 29, 2022, 7:17 PM
I tried but wasnt sure what link to add or what to do
Nov 29, 2022, 7:17 PM
thanks for your help, by messing around with a few things, i added the cors origin, routing in my config file etc ive got it to work.
Nov 29, 2022, 7:55 PM
Oh great!
Nov 29, 2022, 7:55 PM
one question in one of my files, ${process.env.NEXT_PUBLIC_BASE_URL} wont work
Nov 29, 2022, 7:55 PM
but if i put the actual url it does and im not sure why
Nov 29, 2022, 7:56 PM
ye thank you i was able to track down where to go the it was a case of just fiddling about to make it work
Nov 29, 2022, 7:56 PM
Is that base url being used in an API route?
Nov 29, 2022, 7:57 PM
yes
Nov 29, 2022, 7:57 PM
in my fetching from sanity i have it
Nov 29, 2022, 7:58 PM
but its defined in my.env file
Nov 29, 2022, 7:58 PM
That goes back to what I mentioned about absolute URLs earlier. This Stack Overflow thread is really helpful for understanding the concept.
Nov 29, 2022, 7:58 PM
alright ill check it out, honestly thank you for everything i was fed up of it ot working after i finished my site xD
Nov 29, 2022, 7:59 PM
Haha, I've been there, my friend! Glad we got it sorted out!
Nov 29, 2022, 7:59 PM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the 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?