0c7217ba8f
## Feature - [x] Documentation added ## Documentation / Examples - [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples) This PR updates the cms-sanity example to: - Deploy to Vercel with the [Sanity Vercel Integration](https://www.sanity.io/docs/vercel-integration) by default. - You can still opt-out of using the Sanity Vercel Integration, clicking `You can also set up manually` gives you all the information you need. - The blog itself is updated so it's much more resilient to missing data, and is setup to set `revalidate: 60` until you have a On-demand Revalidation webhook setup. - Preview Mode is now enabled on the frontpage as well. - The Sanity client setup, and webhook validation, are updated to follow our current best practices.
18 lines
555 B
JavaScript
18 lines
555 B
JavaScript
let productionUrl
|
|
try {
|
|
productionUrl = new URL(
|
|
process.env.SANITY_STUDIO_PREVIEW_URL || 'http://localhost:3000'
|
|
)
|
|
} catch (err) {
|
|
console.error('Invalid productionUrl', err)
|
|
}
|
|
|
|
export default function resolveProductionUrl(document) {
|
|
if (!productionUrl || !document.slug?.current) {
|
|
return false
|
|
}
|
|
const searchParams = new URLSearchParams()
|
|
searchParams.set('secret', process.env.SANITY_STUDIO_PREVIEW_SECRET || '')
|
|
searchParams.set('slug', document.slug.current)
|
|
return `${productionUrl.origin}/api/preview?${searchParams}`
|
|
}
|