cloudinary-community / next-cloudinary

⚡️ High-performance image delivery and uploading at scale in Next.js powered by Cloudinary.
https://next.cloudinary.dev
MIT License
237 stars 64 forks source link

[Feature] CldImage doesn't support cname, privateCdn or secureDistribution #465

Closed dlepaux closed 3 months ago

dlepaux commented 3 months ago

Feature Request

Cloudinary permits to custom the CDN but next-cloudinary, especially, CldImage, doesn't give access to this.

See your own documentation: https://cloudinary.com/documentation/cloudinary_sdks#cross_sdk_info https://cloudinary.com/documentation/advanced_url_delivery_options#private_cdns_and_cnames https://support.cloudinary.com/hc/en-us/articles/202520562-Can-we-deliver-our-assets-using-a-subdomain-of-our-own-domain-like-cdn-example-com

Potential Solution

As for the configuration of the cloudName NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME="<Your Cloud Name>" in .env file. It would be very much appreciated to have the same way to configure a custom CDN. For example: NEXT_PUBLIC_CLOUDINARY_CNAME="<Your CNAME>"

Or to have a way to pass the CNAME directly to CldImage component.

Thanks

colbyfayock commented 3 months ago

hey @dlepaux CldImage actually supports a config prop where you can do just that!

you can add it with:

<CldImage config={{
 url: {
    secureDistribution: 'spacejelly.dev',
    privateCdn: true
  }
}} />

now unfortunately that isn't globally configurable. one way to support that globally is to create a wrapper component, then use that wrapper component, but that's also not ideal, so perhaps your idea would be a good way to support it globally

part of the issue is Next.js doesn't have an native way for me to be able to add global configurations and i want to avoid adding individual environment variables for every little configuration, but i think cname is likely one that makes sense as an environment variable, particularly because it may change depending on the environment being used

I'll try to work up a PR for this!

dlepaux commented 3 months ago

Hey @colbyfayock ! Thank you for your quick answer.

Do you know if by configuring a custom domain (CNAME), does the regular cloudinary URLs are still valid ?

Thanks

colbyfayock commented 3 months ago

yup! here's an example:

https://cld.fromdesignto.dev/image/upload/v1694695724/cld-sample-4.jpg https://res.cloudinary.com/fromdesigntodev/image/upload/v1694695724/cld-sample-4.jpg

github-actions[bot] commented 3 months ago

:tada: This issue has been resolved in version 6.5.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

colbyfayock commented 3 months ago

in addition to the config prop, privateCdn and secureDistribution are now configurable as environment variables:

NEXT_PUBLIC_CLOUDINARY_SECURE_DISTRIBUTION="<Your Secure Distribution / CNAME>"
NEXT_PUBLIC_CLOUDINARY_PRIVATE_CDN="<true|false>"

i opted not to support the cname property as it's considered legacy and only available in the context of non-secure requests, but let me know if that creates problems

https://cloudinary.com/documentation/cloudinary_sdks#configuration_parameters