Skip to content

briannelson95/sanity-next-client-example

Repository files navigation

This is a Next.js and Sanity.io project. For more documentation on this build, I followed: How to setup Sanity CMS with Next.js & TailwindCSS

Getting Started

First, clone the repo and install dependancies (for both the next app and sanity studio):

yarn install
# and
cd admin
npm install

You'll need to initialize a new sanity project inside of /admin

cd admin
sanity init

Follow the Sanity init instructions in your command line

Then, you can run both the app and the studio from the root:

yarn dev
# and
yarn sanity

There is a script in package.json for yarn sanity that will cd into the admin directory and then runs a sanity start command

Create a .env.local file in the root

NEXT_PUBLIC_SANITY_PROJECT_ID=YOUR_PROJECT_ID
NEXT_PUBLIC_SANITY_DATASET=YOUR_DATASET

Open http://localhost:3000 with your browser to see the frontend next app.

Open http://localhost:3333 with your browser to see the sanity studio.

You can start editing the page by modifying pages/index.js. The page auto-updates as you edit the file.

API routes can be accessed on http://localhost:3000/api/hello. This endpoint can be edited in pages/api/hello.js.

The pages/api directory is mapped to /api/*. Files in this directory are treated as API routes instead of React pages.

Learn More

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!

Deploy on Vercel

Deploy on Vercel like you would any other NextJS app, the build commands will build out the studio first then will deploy the app. You should be able to access your live studio at https://yourdomain.com/admin

Make sure to add .env variables to production on Vercel

NEXT_PUBLIC_SANITY_PROJECT_ID=YOUR_PROJECT_ID
NEXT_PUBLIC_SANITY_DATASET=YOUR_DATASET

The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.

Check out our Next.js deployment documentation for more details.