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?
AI Update

Good news - deploying your Studio and frontend to different locations is totally doable and actually quite common! Here's what you need to know to get this working smoothly.

The Basic Setup

When connecting a new Studio to an existing dataset, you need to configure your Studio's sanity.config.js (or .ts) file with the correct project ID and dataset name. This is your main configuration file where all Studio settings are defined:

import { defineConfig } from 'sanity'
import { deskTool } from 'sanity/desk'

export default defineConfig({
  projectId: 'your-project-id',
  dataset: 'your-existing-dataset',
  plugins: [deskTool()],
  // ... other config
})

Your frontend application uses the same projectId and dataset values when initializing the Sanity client, but they're completely separate deployments.

CORS Configuration - This is Likely Your Issue!

The most common problem when deploying to different locations is CORS (Cross-Origin Resource Sharing) configuration. When your Studio and frontend are on different domains, you need to explicitly allow those domains to access your Sanity project.

Head to manage.sanity.io, navigate to your project, then go to Settings > API > CORS Origins. You'll need to add:

  1. Your Studio URL (e.g., https://your-studio.sanity.studio or wherever you're hosting it)
  2. Your frontend URL (e.g., https://yoursite.com)
  3. For local development: http://localhost:3000 (or whatever port you're using)

Important: Make sure to check the "Allow credentials" box if you're using authentication tokens. This is required when the Access-Control-Allow-Credentials header needs to be set to 'true'.

Deployment Options for Studio

You have a few options for deploying your Studio:

Option 1: Sanity's Hosted Platform (Recommended)

Use the sanity deploy command to deploy to Sanity's hosting:

sanity deploy

This gives you a *.sanity.studio domain, automatically handles schema deployment for platform features like AI Agent Actions, and requires minimal configuration.

Option 2: Self-Hosted

Since Studio is just a React SPA, you can deploy it to Vercel, Netlify, or any other hosting provider. Just make sure to add your deployment URL to CORS origins.

Working with Existing Datasets

If you're specifically trying to copy data from an existing dataset to a new project, you have a couple of options:

  1. CLI Export/Import: Use the Sanity CLI commands to export from one dataset and import to another:

    # Export from existing project
    sanity dataset export production export.ndjson
    
    # Import to new project
    sanity dataset import export.ndjson production
  2. Cross Dataset Duplicator Plugin: Install the @sanity/cross-dataset-duplicator plugin to migrate documents and assets between projects directly from the Studio interface - great if you prefer a GUI approach.

Quick Troubleshooting Checklist

  • ✅ Verify your projectId and dataset match in both Studio and frontend configs
  • ✅ Add all deployment URLs to CORS origins in Sanity Manage
  • ✅ Enable "Allow credentials" for origins using authentication
  • ✅ Double-check protocol (http:// vs https://) - they must match exactly
  • ✅ If using a custom domain, make sure it's added to CORS

The separate deployment approach is actually ideal - it lets you deploy your Studio independently from your frontend, which is perfect for content teams who need Studio access without touching your production site!

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 ?
Hi Geoff! The dataset exists and I essentially dragged the /studio directory from another project and then attempted to reconfigure.
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
Okay, so the trouble is with getting your new Studio set up.
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.
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?
I believe so. I’ve got the same projectId and dataset in both gatsby-config and sanity.json
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
Update: Changes made to Sanity content in local development are now persisting to the frontend in local development
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.
If you go to manage.sanity.io , select your project, click Settings, then API, are all your domains listed under CORS Origins?
Oh. I missed a sentence in your post… I’ll take a look.
To answer your question, my custom deployed domain is listed as a CORS Origin
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
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?
I have a client-config.js file that’s referencing the correct project (I believe)
But no .env file itself
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
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.
By the way, I really appreciate your help! Thank you so much for taking the time to help me figure this out.
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.
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
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?
I believe so
It looks like you have.
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
Last time you deployed, what went wrong?
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.).
What does it say when you open the project at manage.sanity.io ?
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
But I simply added that url in settings &gt; General
When using a subdirectory , I believe you also need to specify it in sanity.json.
Specifying the custom URL as you did should be what makes it render on the manage page.
I’ve updated the basePath to
/studio
I undeployed and am now running
sanity deploy

And we’re live! Thank you so much for your help, Geoff. I wouldn’t have gotten here without you.
Awesome Jacob! It was all you! 🙌
Good luck with the rest of the project. 🙂
Thanks!

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?