Skip to content

Commit 3a83908

Browse files
authored
fix: Fixes Netlify URL (#84)
# Description <!-- Include a summary of the change made and also list the dependencies that are required if any --> ## Issue Ticket Number <!-- Specifiy which issue this fixes by referencing the issue number (`#11`) or issue URL. --> <!-- Example: Fixes #1 --> Fixes #83 ## Type of change <!-- Please select all options that are applicable. --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update # Checklist <!-- These must all be followed and checked. --> - [ ] I have followed the contributing guidelines of this project as mentioned in [CONTRIBUTING.md](/CONTRIBUTING.md) - [ ] I have created an [issue](https://github.com/colbyfayock/netlify-plugin-cloudinary/issues) ticket for this PR - [ ] I have checked to ensure there aren't other open [Pull Requests](https://github.com/colbyfayock/netlify-plugin-cloudinary/pulls) for the same update/change? - [ ] I have performed a self-review of my own code - [ ] I have run tests locally to ensure they all pass - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes needed to the documentation
1 parent 215d366 commit 3a83908

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

netlify-plugin-cloudinary/src/index.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,11 @@ export async function onBuild({
126126
}: OnBuildParams) {
127127
console.log('[Cloudinary] Creating redirects...');
128128

129-
const isProduction = process.env.CONTEXT === 'production';
130-
const host = isProduction
131-
? process.env.NETLIFY_HOST
132-
: process.env.DEPLOY_PRIME_URL;
129+
let host = process.env.URL;
130+
131+
if ( process.env.CONTEXT === 'branch-deploy' || process.env.CONTEXT === 'deploy-preview' ) {
132+
host = process.env.DEPLOY_PRIME_URL || ''
133+
}
133134

134135
console.log(`[Cloudinary] Using host: ${host}`);
135136

@@ -316,10 +317,12 @@ export async function onPostBuild({
316317
}: OnPostBuildParams) {
317318
console.log('[Cloudinary] Replacing on-page images with Cloudinary URLs...');
318319

319-
const isProduction = process.env.CONTEXT === 'production';
320-
const host = isProduction
321-
? process.env.NETLIFY_HOST
322-
: process.env.DEPLOY_PRIME_URL;
320+
let host = process.env.URL;
321+
322+
if ( process.env.CONTEXT === 'branch-deploy' || process.env.CONTEXT === 'deploy-preview' ) {
323+
host = process.env.DEPLOY_PRIME_URL || ''
324+
}
325+
323326

324327
console.log(`[Cloudinary] Using host: ${host}`);
325328

netlify-plugin-cloudinary/tests/on-build.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('onBuild', () => {
6868
fs.readdir.mockResolvedValue([imagesFunctionName]);
6969

7070
process.env.CONTEXT = 'production';
71-
process.env.NETLIFY_HOST = 'https://netlify-plugin-cloudinary.netlify.app';
71+
process.env.URL = 'https://netlify-plugin-cloudinary.netlify.app';
7272

7373
// Tests to ensure that delivery type of fetch works without API Key and Secret as it should
7474

@@ -101,7 +101,7 @@ describe('onBuild', () => {
101101
});
102102
expect(redirects[0]).toEqual({
103103
from: `${imagesPath}/*`,
104-
to: `https://res.cloudinary.com/${process.env.CLOUDINARY_CLOUD_NAME}/image/${deliveryType}/f_auto,q_auto/${process.env.NETLIFY_HOST}/cld-assets${imagesPath}/:splat`,
104+
to: `https://res.cloudinary.com/${process.env.CLOUDINARY_CLOUD_NAME}/image/${deliveryType}/f_auto,q_auto/${process.env.URL}/cld-assets${imagesPath}/:splat`,
105105
status: 302,
106106
force: true
107107
});

netlify.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414

1515
[plugins.inputs]
1616
cloudName = "netlify-cloudinary"
17-
deliveryType = "upload"
17+
# deliveryType = "upload"
1818
imagesPath = [ "images", "screenshots" ]

0 commit comments

Comments
 (0)