-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
3cf2a60
commit d514ad1
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
title: "Adding a Custom Domain" | ||
--- | ||
|
||
Enhance the delivery of your media assets by integrating svelte-cloudinary with a [private CDN and/or custom domain](https://cloudinary.com/documentation/advanced_url_delivery_options#private_cdns_and_custom_delivery_hostnames_cnames). | ||
|
||
:::note | ||
**Private CDN** and **Custom Domain** features are available exclusively on [Cloudinary's Advanced plan](https://cloudinary.com/pricing). | ||
::: | ||
|
||
## Step-by-Step Configuration | ||
|
||
### 1. Install Dependencies | ||
|
||
Ensure you have **svelte-cloudinary** installed in your project: | ||
|
||
```bash | ||
npm install svelte-cloudinary | ||
``` | ||
|
||
### 2. Set Up Environment Variables | ||
|
||
Create a `.env` file in your project root (if it doesn't exist already) and add the following variables: | ||
|
||
```bash | ||
VITE_CLOUDINARY_CLOUD_NAME="your_cloud_name" | ||
VITE_CLOUDINARY_PRIVATE_CDN="true" | ||
VITE_CLOUDINARY_SECURE_DISTRIBUTION="your-custom-domain.com" | ||
``` | ||
Replace your_cloud_name with your actual Cloudinary cloud name and your-custom-domain.com with your custom domain. Read more about [configuring svelte-cloudinary here](https://svelte.cloudinary.dev/config). | ||
|
||
:::caution | ||
Never commit your `.env` file to version control. Add it to your `.gitignore` file to keep sensitive information secure. | ||
::: | ||
|
||
## Example Usage | ||
|
||
With the configuration in place, use the `<CldImage />` component to serve images through your private CDN and custom domain: | ||
|
||
```svelte | ||
<script> | ||
import { CldImage } from 'svelte-cloudinary'; | ||
</script> | ||
<CldImage | ||
src="<Your Public ID>" | ||
alt="Sample Image" | ||
width="800" | ||
height="600" | ||
/> | ||
``` | ||
|
||
This setup ensures that the image URL follows your custom domain structure: | ||
|
||
- **Before:** `https://res.cloudinary.com/your_cloud_name/image/upload/sample.jpg` | ||
- **After:** `https://your-custom-domain.com/image/upload/sample.jpg` | ||
|
||
Learn more about setting up CNAME records on the [Cloudinary docs](https://cloudinary.com/documentation/advanced_url_delivery_options#private_cdns_and_custom_delivery_hostnames_cnames). |