-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cms-sanity] Expose the project id to the browser (#14941)
Fixes #14792 Closes #14814 The project id is currently used by Sanity's image builder, which is used in a React component. @maybac It was faster for me to create a new PR but the credit goes to you, thank you!.
- Loading branch information
Showing
5 changed files
with
20 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
SANITY_PREVIEW_SECRET= | ||
SANITY_PROJECT_ID= | ||
SANITY_API_TOKEN= | ||
NEXT_PUBLIC_SANITY_PROJECT_ID= | ||
SANITY_API_TOKEN= | ||
SANITY_PREVIEW_SECRET= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
import sanityClient from '@sanity/client' | ||
import sanityImage from '@sanity/image-url' | ||
|
||
const options = { | ||
// Find your project ID and dataset in `sanity.json` in your studio project | ||
dataset: 'production', | ||
projectId: process.env.SANITY_PROJECT_ID, | ||
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID, | ||
useCdn: process.env.NODE_ENV === 'production', | ||
// useCdn == true gives fast, cheap responses using a globally distributed cache. | ||
// Set this to false if your application require the freshest possible | ||
// data always (potentially slightly slower and a bit more expensive). | ||
} | ||
|
||
export default sanityClient(options) | ||
const client = sanityClient(options) | ||
|
||
export const imageBuilder = sanityImage(client) | ||
|
||
export const previewClient = sanityClient({ | ||
...options, | ||
useCdn: false, | ||
token: process.env.SANITY_API_TOKEN, | ||
}) | ||
|
||
export default client |