I want to build an array of sites using sanity. I want to be able to create, customize, deploy and assign domain these sites from the CMS i.e. by non technical people. I found this documentation https://vercel.com/guides/nextjs-multi-tenant-application
Is there a way to do this? Is it mandatory to create one vercel project and repo per site?
Yes, you can absolutely build this! You don't need to create one Vercel project and repo per site. Instead, you can use Vercel's multi-tenant architecture with a single Next.js application that serves multiple sites dynamically based on the domain 1.
With Vercel's multi-tenant approach, you have:
Each tenant gets their own domain or subdomain, but you only have one Next.js deployment running on Vercel 1.
Here's how you can structure this with Sanity:
For subdomains like tenant1.yourdomain.com
, add a wildcard domain *.yourdomain.com
to your Vercel project 1.
For custom domains, you can programmatically add them using the Vercel API as shown in the code above 1.
Your Sanity schema would include:
Non-technical users can:
This approach gives you the flexibility of a multi-tenant architecture while maintaining the simplicity of a single codebase and deployment.
To configure the generation, complete these steps:
The code returns the following error:
Configuration must contain `projectId`
at et (@sanity/client)
at r.config (@sanity/client)
at new r (@sanity/client)
at createClient (@sanity/client)
at (/lib/sanity)
Revise the code to address the error.
I was previewing: /
I'll fix the Sanity client configuration error by adding the required projectId
and other necessary configuration options.
The error was occurring because the Sanity client requires a projectId
to connect to your Sanity project. Here's what I've fixed:
projectId
, dataset
, useCdn
, and apiVersion
To complete the setup:
Get your Sanity Project ID:
your-sanity-project-id
in the .env.local
fileSet up your dataset:
production
as the dataset nameAdd a Sanity token (if you need write access):
The configuration should now work without the projectId
error.
To configure the generation, complete these steps: