How to host both Sanity Studio and Frontend on the same Netlify site

13 replies
Last updated: May 14, 2021
Hey people! how does hosting both your sanity studio and your FE on the same netlify site work? I did find a guide on the guide page but it returned 404. I got the FE up and running but i’d like to access the studio on the same url but like /admin or /dashboard or whatever 🙂 everything is in the same github repo
AI Update

Great question! Hosting both your Sanity Studio and frontend on the same Netlify site from a single repo is totally doable. Here's how to set it up:

The Key Configuration: basePath

In your Sanity Studio config file (sanity.config.ts or sanity.config.js), you need to set a basePath to tell Studio it's living at a sub-route:

import {defineConfig} from 'sanity'

export default defineConfig({
  projectId: 'your-project-id',
  dataset: 'your-dataset',
  basePath: '/admin', // or /studio, /dashboard, whatever you prefer
  // ... rest of your config
})

Routing Setup

You have two main approaches depending on your frontend framework:

Option 1: Framework with Catch-All Routes (Next.js, Nuxt, etc.)

If you're using Next.js, create a catch-all route like app/admin/[[...index]]/page.tsx (App Router) or pages/admin/[[...index]].tsx (Pages Router):

// app/admin/[[...index]]/page.tsx
import {Studio} from 'sanity'
import config from '../../../sanity.config'

export default function StudioPage() {
  return <Studio config={config} />
}

The [[...index]] pattern ensures all sub-routes under /admin get handled by the Studio.

Option 2: Netlify Redirects (Static Sites)

If you're not using a framework with built-in routing (or deploying a static build), you need to configure Netlify redirects. Create a netlify.toml file in your repo root:

[[redirects]]
  from = "/admin/*"
  to = "/admin"
  status = 301
  force = true

According to the Sanity embedding documentation, this redirect ensures all routes under /admin are properly handled by the Studio's client-side routing.

Important: CORS Settings

Don't forget to add your Netlify domain to your Sanity project's CORS origins settings with credentials enabled. Go to your project settings at manage.sanity.io and add:

  • https://your-site.netlify.app (production)
  • http://localhost:3000 (or whatever port you use locally)

Full Styling Requirement

The Studio needs to take full viewport height. Add this CSS wherever your /admin route renders:

#app {
  height: 100vh;
  max-height: 100dvh;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  overflow: auto;
}

Monorepo Structure

Since everything's in the same repo, a typical structure looks like:

my-project/
├── sanity.config.ts    # Studio config
├── app/                # Your Next.js app (or other framework)
│   └── admin/[[...index]]/page.tsx
├── schemas/            # Sanity schemas
├── netlify.toml        # If using redirects
└── package.json

For more details, check out the Embedding Sanity Studio docs and the next-sanity library if you're using Next.js specifically.

The setup works great on Netlify - you'll have your frontend at the root and Studio accessible at whatever path you choose! 🎉

Hey Oskar! The process for deploying should be the same as in this guide .You would need to make sure that you’ve configured single-page application routing on Netlify and added the domain where you’re hosting the Studio as a
valid domain in manage.sanity.io . Then, you would specify the
basePath
in
sanity.json
as
/admin
or
/dashboard
And as a side note, you could add this plugin to easily trigger new builds of your FE from your dashboard!
Hey Oskar! The process for deploying should be the same as in this guide .You would need to make sure that you’ve configured single-page application routing on Netlify and added the domain where you’re hosting the Studio as a
valid domain in manage.sanity.io . Then, you would specify the
basePath
in
sanity.json
as
/admin
or
/dashboard
Hey
user M
, thanks for the answer 😄Im not really sure how that would work considering i have to specify the build command and the publish directory.. and if i have a project repo and the structure for it is

project/
    web/
    studio/
how would i go on to setup the build settings for the netlify site?
Might just be me who doesnt understand it, because atm to only build the FE i set the baseDirectory to
/web
and the build command to
next build && next export
and then the publish directory to
/web/out
So i dont know how to get the sanity folder
/studio
into that solution..
OK, if I’m understanding correctly, you’re not sure how to get the studio to build at the domain you specify?
If so, you would follow the steps in the guide I shared above then run
sanity deploy
in order to have the studio deploy. You wouldn’t need to include the studio in your next build.
Let me know if I’m getting your goal wrong!
Okay so what you’re saying is that if i have my github repository (including both the
/web
and
/studio
) on netlify and the build settings is what i stated before, e.g the commands to build the nextjs application, I dont have to do
sanity build
if i want to be able to access the studio on the same netlify url but on
websiteUrl/admin
? I just have to deploy with a specified build path in sanity.json?
Okay so what you’re saying is that if i have my github repository (including both the
/web
and
/studio
) on netlify and the build settings is what i stated before, e.g the commands to build the nextjs application, I dont have to do
sanity build
if i want to be able to access the studio on the same netlify url but on
websiteUrl/admin
? I just have to deploy with a specified build path in sanity.json?
Exactly
Do i have to state the full url or just /admin in the build path?
It would just be the /admin build path but you would have to add the domain to your CORS origins in manage.sanity.io
alright sweet! 😄 Thank you so much🤗
Of course! Good luck!

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?