sanity
sanity copied to clipboard
Production Preview: default async resolveProductionUrl export
Is your feature request related to a problem? Please describe.
https://www.sanity.io/docs/preview-content-on-site
When using production preview, I would like to be able to configure the environment to preview by leveraging a plugin. Something along the lines of.
// ./resolveProductionUrl.js
import client from 'part:@sanity/base/client';
const previewSecret = 'MY_SECRET'
const PREVIEW_QUERY = `*[_type == "preview_environment_storage"] | order(_createdAt desc)`;
export default async function resolveProductionUrl(document) {
const documentType = document._type;
const [configuredHost] = await client.fetch(PREVIEW_QUERY);
return `${configuredHost.url}/api/preview?secret=${previewSecret}&type=${documentType}&slug=${document.slug.current}`
}
where preview_environment_storage
gets managed by plugin.
Describe the solution you'd like
Update the calling context of resolveProductionUrl.js
to expect a promise that resolves a url.
Describe alternatives you've considered
Storing the environment in local storage instead of as a sanity type. Using an env variable to differentiate between development and production mode
- Env variables work great for a local, prod setup, currently using local, test, prod setup
Additional context
Alternative suggestion: make it possible to use env vars, even SANITY_STUDIO_*
would be great
This should now be easier to do in Sanity Studio v3, since the configuration is fully javascript based.