Skip to content

Commit

Permalink
fix: gatsbyImageData generates http urls, not https (#210)
Browse files Browse the repository at this point in the history
fixes #209
  • Loading branch information
raae committed Nov 30, 2022
1 parent 0503b7f commit 3508cd3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,13 @@ The style of the temporary image shown while the larger image is loaded.
Go to the [Gatsby Plugin Image Docs](https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-plugin-image/#placeholder) for more information.

#### `secure`

When set to `false` uses `http` instead of `https` for the image urls.

**Type:** `Boolean`
**Default:** `true`

#### `height` / `width`

Go to the [Gatsby Plugin Image Docs](https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-plugin-image/#widthheight) for information on `height` / `width`.
Expand Down
2 changes: 1 addition & 1 deletion plugin/gatsby-plugin-image/generate-asset-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ exports.generateCloudinaryAssetUrl = ({
transformation.push(generateTracedSVGTransformation(tracedSvg));
}

cloudinary.config({ cloud_name: cloudName });
cloudinary.config({ cloud_name: cloudName, secure: options.secure });

const url = cloudinary.url(publicId, {
transformation,
Expand Down
12 changes: 12 additions & 0 deletions plugin/gatsby-plugin-image/generate-asset-url.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ describe('generateCloudinaryAssetUrl', () => {
);
});

it('generates correct Cloudinary url with scure option set to true', () => {
const url = generateCloudinaryAssetUrl({
...asset,
options: {
secure: true,
},
});
expect(url).toBe(
'https://res.cloudinary.com/cloud-name/image/upload/f_jpg,h_600,w_400/public-id'
);
});

it('generates correct Cloudinary url in traced SVG mode', () => {
const url = generateCloudinaryAssetUrl({
...asset,
Expand Down
3 changes: 2 additions & 1 deletion plugin/gatsby-plugin-image/resolve-asset.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('generateCloudinaryAssetSource', () => {
const fit = undefined;
const options = {
chained: ['t_lwj'],
secure: true,
};
it('generated correct source data', () => {
const result = _generateCloudinaryAssetSource(
Expand All @@ -48,7 +49,7 @@ describe('generateCloudinaryAssetSource', () => {
);

expect(result.src).toBe(
'http://res.cloudinary.com/cloud-name/image/upload/f_jpg,h_500,w_300/t_lwj/public-id'
'https://res.cloudinary.com/cloud-name/image/upload/f_jpg,h_500,w_300/t_lwj/public-id'
);
expect(result.width).toBe(width);
expect(result.height).toBe(height);
Expand Down
4 changes: 4 additions & 0 deletions plugin/gatsby-plugin-image/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ exports.createGatsbyPluginImageResolver = (gatsbyUtils, pluginOptions) => {
placeholder: {
type: CloudinaryPlaceholderType,
},
secure: {
type: 'Boolean',
defaultValue: true,
},
}
);
} catch (error) {
Expand Down

0 comments on commit 3508cd3

Please sign in to comment.