Host Sanity Studio in subdirectory

I am looking for a way to deploy the Sanity Studio in a subdirectory on my Next.js site. I need it to be www.example.com/studio.

I can find Sanity documentation (Hosting and deployment) on changing the “basePath” in sanity.json, but this method uses the Sanity CLI command “sanity build” to create static files to be hosted.

With Next.js using the Pages directory to create routes, and netlify pulling from git, I am unsure of how to have my studio publish to a subdirectory.

Hi @BrandonLeb,

The short answer would be this is tough. Building 2 websites in one build command not something that is expected to work out of the box, but you can try something like this:

Considering you’ve a structure like this:

.
├── next
│   ├── files
│   ├── public
│   └── next_build
└── sanity
    ├── files
    └── sanity_build

You’d have to do something like:

cd ./sanity && <sanity-build-command> && cp -r ./sanity_build ../next/public/subdirectory && cd ../next && <next-build-command>

This command assumes that yourSanity built files would be placed inside sanity_build and NextJS has a public folder which is useful for unmodified files. So, anything that you place in that folder would basically be served from the root. So, you’d have to build Sanity, copy those files to NextJS’ public directory and then run NextJS’ build.