Unlock seamless workflows and faster delivery with our latest releases- get the details

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

18 replies
Last updated: Nov 23, 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";

// <https://astro.build/config>
export default defineConfig({
  output: 'hybrid',
  integrations: [tailwind(), svelte(), sanity({
    projectId: '<actualProjectID>',
    dataset: 'production',
    useCdn: false,
    studioBasePath: '/admin'
  }), react()],
  adapter: netlify()
});
Sep 11, 2023, 4:51 PM
Looks right to me. Did you also add the
sanity.config.ts
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: '<actualProjectName>',
  title: '<actualProjectTitle>',

  projectId: '<actualProjectID>',
  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
admin
folder and put the
sanity.config.ts
file in root (alongside
astro.config.mjs
)
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
astro.config.mjs
) 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
pages
folder 🙂
Sep 11, 2023, 5:26 PM
Sep 11, 2023, 5:26 PM
(I guess we could move the
schema
into the
src
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
// <https://docs.astro.build/en/guides/configuring-astro/#environment-variables>
import { loadEnv } from 'vite';
const { PUBLIC_SANITY_STUDIO_PROJECT_ID, PUBLIC_SANITY_STUDIO_DATASET } =
  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';

// <https://astro.build/config>
export default defineConfig({
  output: 'hybrid',
  adapter: netlify(),
  integrations: [
    sanity({
      projectId: PUBLIC_SANITY_STUDIO_PROJECT_ID,
      dataset: PUBLIC_SANITY_STUDIO_DATASET,
      studioBasePath: '/admin',
      useCdn: false,
      // `false` if you want to ensure fresh data
      apiVersion: '2023-03-20',
    }),
    react(),
    tailwind(),
  ],
});
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
Hello! I just encountered the problem.
I found something interesting that might help you
user N
, it worked for me.
It should work if you go to yoururl/admin/desk.

I noticed in the dist/_redirects file that redirection for admin path was "/admin/*"
Nov 23, 2023, 2:35 PM
Let’s use greetings like “Hey Everyone,” “Hi, Y’all," or “Hello, Folks” to make sure everyone in the community is included. Please read the Sanity Community Code of Conduct to stay updated on expected communication &amp; behavior in our spaces: https://www.sanity.io/docs/community-code-of-conduct
Nov 23, 2023, 2:35 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?