Issue with embedding Sanity Studio into an Astro site, resolved with help from the community.

16 replies
Last updated: Sep 19, 2023
Hi there,I’m trying to embed the sanity studio into my new astro site.
I’ve followed along with this
documentation , but keep getting a 404 error.
I have the studio installed in a ‘admin’ folder in the root folder of my astro project.
Is there an issue with my astro config?

import { defineConfig } from 'astro/config';
import tailwind from '@astrojs/tailwind';
import svelte from '@astrojs/svelte';
import sanity from 'astro-sanity';
import react from '@astrojs/react';

import netlify from "@astrojs/netlify/functions";

// <>
export default defineConfig({
  output: 'hybrid',
  integrations: [tailwind(), svelte(), sanity({
    projectId: '&lt;actualProjectID&gt;',
    dataset: 'production',
    useCdn: false,
    studioBasePath: '/admin'
  }), react()],
  adapter: netlify()
Sep 11, 2023, 4:51 PM
Looks right to me. Did you also add the
file? Do you have the code on GitHub by any chance?
Sep 11, 2023, 4:53 PM
Yes, it’s sitting under /admin

import {defineConfig} from 'sanity'
import {deskTool} from 'sanity/desk'
import {visionTool} from '@sanity/vision'
import {schemaTypes} from './schemas'

export default defineConfig({
  name: '&lt;actualProjectName&gt;',
  title: '&lt;actualProjectTitle&gt;',

  projectId: '&lt;actualProjectID&gt;',
  dataset: 'production',

  plugins: [deskTool(), visionTool()],

  schema: {
    types: schemaTypes,
Sep 11, 2023, 4:54 PM
No repo currently, but I can get one up if need be.
Sep 11, 2023, 4:54 PM
I should be able to run the studio at /admin while in dev as well right?
Or is the embed just for production when I have the site up on Netlify?
Sep 11, 2023, 4:59 PM
Ah – try to remove the
folder and put the
file in root (alongside
Sep 11, 2023, 5:04 PM
that’s not clear perhaps
Sep 11, 2023, 5:04 PM
Hmm, moved the file to the root (alongside
) and installed the file’s dependencies in the root as well.
Where should I be storing the studio specific files then?
Sep 11, 2023, 5:15 PM
Anywhere you want, except in the
folder 🙂
Sep 11, 2023, 5:26 PM
Sep 11, 2023, 5:26 PM
(I guess we could move the
into the
folder, and so on)
Sep 11, 2023, 5:27 PM
Thank you for linking this.It’s a completely fresh project, so I just started over with this template and all is working now.
Sep 11, 2023, 5:39 PM
Thanks for your help!
Sep 11, 2023, 5:40 PM
Awesome! I’ll make sure to make the docs a bit clearer 🙇‍♂️
Sep 11, 2023, 5:40 PM
So I'm having similar issues with deployment now.The studio just 404s in production, even though I have enabled CORs for the origin.

My astro config:

import { defineConfig } from 'astro/config';

// Loading environment variables from .env files
// <>
import { loadEnv } from 'vite';
  loadEnv(import.meta.env.MODE, process.cwd(), '');

import sanity from '@sanity/astro';
import react from '@astrojs/react';
import netlify from '@astrojs/netlify/functions';
import tailwind from '@astrojs/tailwind';

// <>
export default defineConfig({
  output: 'hybrid',
  adapter: netlify(),
  integrations: [
      studioBasePath: '/admin',
      useCdn: false,
      // `false` if you want to ensure fresh data
      apiVersion: '2023-03-20',
Sep 18, 2023, 4:42 PM
If it only happens in production, are you sure that your build has access to your environment variables?
Sep 19, 2023, 9:11 PM
The site itself is working, just not the studio.
The only variables I've configured are the project ID and dataset.
Sep 19, 2023, 9:13 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?

Categorized in