Skip to content

Commit

Permalink
feat(gatsby-plugin-utils): make image cdn urls configurable (#37932)
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerBarnes authored Apr 12, 2023
1 parent ba2a45f commit 792937c
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ function appendUrlParamToSearchParams(
searchParams.append(paramName, finalUrl)
}

const frontendHostName = process.env.IMAGE_CDN_HOSTNAME || ``

export function generateFileUrl(
{
url,
Expand All @@ -78,7 +80,7 @@ export function generateFileUrl(

appendUrlParamToSearchParams(parsedURL.searchParams, url)

return `${parsedURL.pathname}${parsedURL.search}`
return `${frontendHostName}${parsedURL.pathname}${parsedURL.search}`
}

export function generateImageUrl(
Expand Down Expand Up @@ -107,9 +109,11 @@ export function generateImageUrl(
source.internal.contentDigest
)

return `${parsedURL.pathname}${parsedURL.search}`
return `${frontendHostName}${parsedURL.pathname}${parsedURL.search}`
}

const routePrefix = process.env.IMAGE_CDN_ROUTE_PREFIX || `_gatsby`

function generatePublicUrl(
{
url,
Expand All @@ -130,7 +134,9 @@ function generatePublicUrl(

let publicUrl =
pathPrefix +
(mimeType && isImage({ mimeType }) ? `/_gatsby/image/` : `/_gatsby/file/`)
(mimeType && isImage({ mimeType })
? `/${routePrefix}/image/`
: `/${routePrefix}/file/`)

publicUrl += `${remoteUrl}`

Expand Down

0 comments on commit 792937c

Please sign in to comment.