From 72a4d8898b303ef079412f2d458526348db0fb55 Mon Sep 17 00:00:00 2001 From: Espen Hovlandsdal Date: Thu, 17 Feb 2022 14:29:07 -0800 Subject: [PATCH] docs: add docs on custom CDN domains --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/README.md b/README.md index 220b1d2..73b71da 100644 --- a/README.md +++ b/README.md @@ -139,3 +139,42 @@ Specify the number of pixels to pad the image. Specifies min/max dimensions when cropping. **Deprecated**: You usually want to use `width`/`height` with a fit mode of `max` or `min` instead. + +## Custom CDN domains + +You can specify a custom `baseUrl` in the builder options in order to override the default (`https://cdn.sanity.io`): + +```js +import imageUrlBuilder from '@sanity/image-url' + +const builder = imageUrlBuilder({ + baseUrl: 'https://my.custom.domain', + projectId: 'abc123', + dataset: 'production', +}) +const urlFor = (source) => builder.image(source) + +urlFor('image-928ac96d53b0c9049836c86ff25fd3c009039a16-200x200-png') + .auto('format') + .fit('max') + .width(720) + .toString() + +// output: https://my.custom.domain/images/abc123/production/928ac96d53b0c9049836c86ff25fd3c009039a16-200x200.png?auto=format&fit=max&w=720 +``` + +If you already have a configured client instance: + +```js +import imageUrlBuilder from '@sanity/image-url' +import myConfiguredClient from './mySanityClient' + +const builder = imageUrlBuilder({ + ...myConfiguredClient.config(), + baseUrl: 'https://my.custom.domain', +}) +``` + +## License + +MIT © [Sanity.io](https://www.sanity.io/)