@@ -14,30 +14,25 @@ function uploadcareLoader({ src, width, quality }) {
1414 const proxyEndpoint = customProxyEndpoint || ( 0 , helpers_1 . generateDefaultProxyEndpoint ) ( publicKey ) ;
1515 const basePath = ( 0 , helpers_1 . trimTrailingSlash ) ( process . env . NEXT_PUBLIC_UPLOADCARE_APP_BASE_URL || '' ) ;
1616 const proxy = ( 0 , helpers_1 . trimTrailingSlash ) ( proxyEndpoint ) ;
17- const isOnCdn = ( 0 , helpers_1 . isCdnUrl ) ( src , cdnDomain ) ;
18- if ( ! ( 0 , helpers_1 . isProduction ) ( ) && ! isOnCdn ) {
17+ const isProductionMode = ( 0 , helpers_1 . isProduction ) ( ) ;
18+ const isImageOnCdn = ( 0 , helpers_1 . isCdnUrl ) ( src , cdnDomain ) ;
19+ const isImageRelative = src . startsWith ( '/' ) ;
20+ // Development mode; not on CDN.
21+ if ( ! isProductionMode && ! isImageOnCdn ) {
1922 const isPublicKeySet = ! ( 0 , helpers_1 . isDotenvParamEmpty ) ( publicKey ) ;
2023 const isCustomProxyEndpointSet = ! ( 0 , helpers_1 . isDotenvParamEmpty ) ( customProxyEndpoint ) ;
2124 if ( ! isPublicKeySet && ! isCustomProxyEndpointSet ) {
2225 throw new Error ( `Both NEXT_PUBLIC_UPLOADCARE_PUBLIC_KEY and NEXT_PUBLIC_UPLOADCARE_CUSTOM_PROXY_DOMAIN are not set. Please set either one.` ) ;
2326 }
24- if ( src . startsWith ( '/' ) ) {
27+ if ( isImageRelative ) {
2528 return src ;
2629 }
2730 }
28- // Process local images in Production.
29- if ( ( 0 , helpers_1 . isProduction ) ( ) && ! isOnCdn && src . startsWith ( '/' ) ) {
30- const isBasePathSet = ! ( 0 , helpers_1 . isDotenvParamEmpty ) ( basePath ) ;
31- if ( ! isBasePathSet ) {
32- return src ;
33- }
34- return `${ basePath } ${ src } ` ;
35- }
3631 const filename = ( 0 , helpers_1 . getFilename ) ( src ) ;
3732 const extension = ( 0 , helpers_1 . getExtension ) ( filename ) ;
3833 // Some extensions are not processed by Uploadcare, e.g. SVG.
3934 if ( constants_1 . NOT_PROCESSED_EXTENSIONS . includes ( extension ) ) {
40- return isOnCdn ? src : `${ basePath } ${ src } ` ;
35+ return isImageOnCdn ? src : `${ basePath } ${ src } ` ;
4136 }
4237 // Demo: https://ucarecdn.com/a6f8abc8-f92e-460a-b7a1-c5cd70a18cdb/-/format/auto/-/resize/300x/vercel.png
4338 const userParams = ( 0 , helpers_1 . parseUserParamsString ) ( userParamsString ) ;
@@ -52,10 +47,19 @@ function uploadcareLoader({ src, width, quality }) {
5247 ] ) ;
5348 const params = ( 0 , helpers_1 . mergeParams ) ( basicParams , userParams ) ;
5449 const apiParamsString = '/-/' + params . join ( '/-/' ) + '/' ;
55- if ( isOnCdn ) {
50+ if ( isImageOnCdn ) {
5651 const withoutFilename = src . slice ( 0 , src . lastIndexOf ( '/' ) ) ;
5752 return `${ withoutFilename } ${ apiParamsString } ${ filename } ` ;
5853 }
54+ // Production mode; local image.
55+ if ( isProductionMode && isImageRelative ) {
56+ const isBasePathSet = ! ( 0 , helpers_1 . isDotenvParamEmpty ) ( basePath ) ;
57+ // Return the relative url AS IS if the base path is not set.
58+ if ( ! isBasePathSet ) {
59+ return src ;
60+ }
61+ return `${ proxy } ${ apiParamsString } ${ basePath } ${ src } ` ;
62+ }
5963 return `${ proxy } ${ apiParamsString } ${ src } ` ;
6064}
6165exports . uploadcareLoader = uploadcareLoader ;
0 commit comments