Skip to content

Commit ba5bc3d

Browse files
authored
chore: update Image CDN docs for more correct patterns (#732)
1 parent d945226 commit ba5bc3d

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

docs/image-cdn.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ all plans.
99
## Enabling the Image CDN
1010

1111
To enable the Image CDN, you should set the environment variable
12-
`NETLIFY_IMAGE_CDN` to `true`. You will also need to declare allowed image URL
13-
patterns in `netlify.toml`:
12+
`NETLIFY_IMAGE_CDN` to `true`. You will also need to declare allowed remote
13+
image regular expression patterns in `netlify.toml`:
1414

1515
```toml
1616
[build.environment]
1717
NETLIFY_IMAGE_CDN = "true"
1818

1919
[images]
2020
remote_images = [
21-
'https://example1.com/*',
22-
'https://example2.com/*'
21+
'^https:\\/\\/example1\\.com\\/.*',
22+
'^https:\\/\\/example2\\.com\\/.*'
2323
]
2424
```
2525

26-
Exact URL patterns to use will depend on CMS you use and possibly your
26+
Exact remote image pattern to use will depend on CMS you use and possibly your
2727
configuration of it.
2828

2929
- `gatsby-source-contentful`:
@@ -33,7 +33,7 @@ configuration of it.
3333
remote_images = [
3434
# <your-contentful-space-id> is specified in the `spaceId` option for the
3535
# gatsby-source-contentful plugin in your gatsby-config file.
36-
"https://images.ctfassets.net/<your-contentful-space-id>/*"
36+
"^https:\\/\\/images\\.ctfassets\\.net\\/<your-contentful-space-id>\\/.*"
3737
]
3838
```
3939

@@ -44,7 +44,7 @@ configuration of it.
4444
remote_images = [
4545
# <your-drupal-base-url> is speciafied in the `baseUrl` option for the
4646
# gatsby-source-drupal plugin in your gatsby-config file.
47-
"<your-drupal-base-url>/*"
47+
"^<your-drupal-base-url>\\/.*"
4848
]
4949
```
5050

@@ -56,14 +56,21 @@ configuration of it.
5656
# <your-wordpress-url> is specified in the `url` option for the
5757
# gatsby-source-wordpress plugin in your gatsby-config file.
5858
# There is no need to include `/graphql in the path here`
59-
"<your-wordpress-url>/*"
59+
"^<your-wordpress-url>\\/.*"
6060
]
6161
```
6262

6363
Above examples are the most likely ones to be needed. However if you configure
6464
your CMS to host assets on different domain or path, you might need to adjust
6565
the patterns accordingly.
6666

67+
Keep in mind that you will need to escape special regular expression symbols to
68+
avoid creating too permisible patterns:
69+
70+
- `.` should be escaped as `\\.` (dot)
71+
- `/` should be escaped as `\\/` (slash)
72+
- your rule should start with `^` so domain matching is exact
73+
6774
## How it works
6875

6976
When using the Image CDN, Gatsby generates URLs of the form

0 commit comments

Comments
 (0)