Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Trouble deploying Sanity studio and frontend to different locations, seeking help and guidance.

39 replies
Last updated: Apr 2, 2021
Hi all, has anyone had luck deploying their studio and frontend to different locations? I’ve created a new project and want to use an existing dataset, but I’m having a lot of trouble. Can anyone point me in the right direction?
Apr 2, 2021, 5:06 PM
Hi Jacob. To clarify, are you saying the Sanity project already exists and you now want to query it from a different front end? If that’s the case, are you using the JavaScript client ?
Apr 2, 2021, 5:22 PM
Hi Geoff! The dataset exists and I essentially dragged the /studio directory from another project and then attempted to reconfigure.
Apr 2, 2021, 5:25 PM
I have @client/sanity installed but have not been using it. As this is only my second Sanity project, I’m still familiarizing myself with GraphQL and have not begun learning GROQ
Apr 2, 2021, 5:26 PM
Okay, so the trouble is with getting your new Studio set up.
Apr 2, 2021, 5:26 PM
Yep. Previously in the development of this project, I was able to to publish new content and view it on my deployed frontend after pushing my code and redeploying to Netlify, but in an attempt to clean up the studio and deploy it to my client, I broke something and now new content is not pushing to the frontend—locally or otherwise.
Apr 2, 2021, 5:28 PM
Is your front end querying the same Sanity project that you’re now working with? I.e., do the project details in studio/sanity.json match those on your front end?
Apr 2, 2021, 5:29 PM
I believe so. I’ve got the same projectId and dataset in both gatsby-config and sanity.json
Apr 2, 2021, 5:32 PM
But in local development, my Sanity studio is pointing to a deprecated frontend and a deployed studio that’s giving me CORS issues after I accidentally deleted a whitelisted URL
Apr 2, 2021, 5:33 PM
Update: Changes made to Sanity content in local development are now persisting to the frontend in local development
Apr 2, 2021, 5:39 PM
So I suppose the scope of my issue is with the Sanity studio itself. The site under Netlify sites is correct, but the Studio and Frontend under Apps are incorrect. I’ve attempted to make changes to studio/dashboardConfig.js, but that didn’t seem to work. I’ve read Sanity’s docs on hosting and deploying, but I’m lost and on a deadline.
Apr 2, 2021, 5:43 PM
If you go to manage.sanity.io , select your project, click Settings, then API, are all your domains listed under CORS Origins?
Apr 2, 2021, 5:48 PM
Oh. I missed a sentence in your post… I’ll take a look.
Apr 2, 2021, 5:52 PM
To answer your question, my custom deployed domain is listed as a CORS Origin
Apr 2, 2021, 5:52 PM
Based on the docs, I was under the impression that with a url of davidodyssey.com , davidodyssey.com/studio would be the location of the deployed studio
Apr 2, 2021, 5:53 PM
Some projects are configured with the studio as a subdirectory of the project. Many others keep the two separate. For example, the Sanity Gatsby Blog template appears to deploy the studio and the Gatsby front end to two different Netlify sites. For my projects, I usually deploy the front end to Vercel and the studio to <project>.sanity.studio.
Do you possibly have a .env file that’s referencing the wrong project in production?
Apr 2, 2021, 6:01 PM
I have a client-config.js file that’s referencing the correct project (I believe)
Apr 2, 2021, 6:03 PM
But no .env file itself
Apr 2, 2021, 6:03 PM
In my original project, I had separate /web and /studio directories for the frontend. In this current iteration, I have the /studio directory in the root of my project
Apr 2, 2021, 6:04 PM
I’d happily deploy my Sanity studio to Sanity, and since I used a basic Gatsby starter, I don’t think the studio is automatically being deployed to a Netlify site as it would be with the blog starter. Could be wrong about that though.
Apr 2, 2021, 6:05 PM
By the way, I really appreciate your help! Thank you so much for taking the time to help me figure this out.
Apr 2, 2021, 6:05 PM
No problem! Just hope you can get this sorted! I don’t work much in Gatsby and Netlify so apologies if I ask something that’s not applicable.
To sum up so far, everything is working in development locally. You can access your studio at localhost:3333 and your front end is running on localhost:8080 or whatever and is pulling in the data from that studio.
Apr 2, 2021, 6:11 PM
Correct. I’m also able to publish new content by triggering a redeploy. What I’ve never done before, and what I’m hesitant to do without help / after almost breaking my whole project a couple days ago, is properly deploying my Sanity studio
Apr 2, 2021, 6:14 PM
I see. I’d be afraid to give advice since I don’t want to put you in a place where the same thing happens again. Have you deployed your GraphQL playground?
Apr 2, 2021, 6:32 PM
I believe so
Apr 2, 2021, 6:33 PM
It looks like you have.
Apr 2, 2021, 6:33 PM
Once I got the right data persisting to the front end, I’ve tried to stay away from messing with GraphQL as much as possible haha
Apr 2, 2021, 6:33 PM
Last time you deployed, what went wrong?
Apr 2, 2021, 6:34 PM
I’m just not sure where to find the deployed studio. Changes made to studio/dashboard.config change the corresponding data, but that doesn’t necessarily mean the data itself is valid (I realize that doesn’t make a ton of sense, I’m sorry.).
Apr 2, 2021, 6:35 PM
What does it say when you open the project at manage.sanity.io ?
Apr 2, 2021, 6:36 PM
In other words, if I make changes here:
data: [
          {
            title: 'GitHub repo',
            value: '<https://github.com/Jacob-Fromm/odyssey-sanity-gatsby-netlify-v8>',
            category: 'Code'
          },
          {
            title: 'Frontend',
            value: '<https://odyssey-sanity-gatsby-netlify-v-8.netlify.app>',
            category: 'apps'
          }
        ]
then new data appears in my local Sanity studio, but I don’t think that’s doing anything on a deep level
Apr 2, 2021, 6:36 PM
But I simply added that url in settings &gt; General
Apr 2, 2021, 6:39 PM
When using a subdirectory , I believe you also need to specify it in sanity.json.
Apr 2, 2021, 6:39 PM
Specifying the custom URL as you did should be what makes it render on the manage page.
Apr 2, 2021, 6:40 PM
I’ve updated the basePath to
/studio
Apr 2, 2021, 6:42 PM
I undeployed and am now running
sanity deploy

Apr 2, 2021, 6:46 PM
And we’re live! Thank you so much for your help, Geoff. I wouldn’t have gotten here without you.
Apr 2, 2021, 6:48 PM
Awesome Jacob! It was all you! 🙌
Apr 2, 2021, 6:48 PM
Good luck with the rest of the project. 🙂
Apr 2, 2021, 6:49 PM
Thanks!
Apr 2, 2021, 6:49 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?