Skip to content

Commit

Permalink
[image-url] Allow specifying a baseUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Mar 20, 2018
1 parent 2628cee commit 3a56ba2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/@sanity/image-url/src/builder.js
Expand Up @@ -154,6 +154,7 @@ export default function urlBuilder(options) {
if (options && typeof options.clientConfig == 'object') {
// Inherit config from client
return new ImageUrlBuilder(null, {
baseUrl: options.clientConfig.apiHost.replace(/^https:\/\/api\./, 'https://cdn.'),
projectId: options.clientConfig.projectId,
dataset: options.clientConfig.dataset
})
Expand Down
6 changes: 3 additions & 3 deletions packages/@sanity/image-url/src/urlForImage.js
Expand Up @@ -138,9 +138,9 @@ function parseAssetId(ref) {

/* eslint-disable complexity */
function specToImageUrl(spec) {
const baseUrl = `https://cdn.sanity.io/images/${spec.projectId}/${spec.dataset}/${
spec.asset.id
}-${spec.asset.width}x${spec.asset.height}.${spec.asset.format}`
const cdnUrl = spec.baseUrl || 'https://cdn.sanity.io'
const filename = `${spec.asset.id}-${spec.asset.width}x${spec.asset.height}.${spec.asset.format}`
const baseUrl = `${cdnUrl}/images/${spec.projectId}/${spec.dataset}/${filename}`

const params = []

Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/image-url/test/urlForHotspotImage.test.js
@@ -1,5 +1,5 @@
import urlForHotspotImage from '../src/urlForImage'
import should from 'should'
import urlForHotspotImage from '../src/urlForImage'
import {uncroppedImage, croppedImage, noHostpotImage} from './fixtures'

describe('urlForHotspotImage', () => {
Expand Down

0 comments on commit 3a56ba2

Please sign in to comment.