Skip to content

Commit 2d11183

Browse files
Merge branch 'main' into mk/middleware-package
2 parents 692ea63 + 40cb8a9 commit 2d11183

File tree

11 files changed

+147
-47
lines changed

11 files changed

+147
-47
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ In order to deliver the correct format to a visitor's browser, this uses a Netli
5353
site may not support Edge Functions, in which case it will instead fall back to delivering the original file format. You
5454
may also manually disable the Edge Function by setting the environment variable `NEXT_DISABLE_EDGE_IMAGES` to `true`.
5555

56+
## Returning custom response headers on images handled by `ipx`
57+
58+
Should you wish to return custom response headers on images handled by the [`netlify-ipx`](https://github.com/netlify/netlify-ipx) package, you can add them within your project's `netlify.toml` by targeting the `/_next/image/*` route:
59+
60+
```
61+
[[headers]]
62+
for = "/_next/image/*"
63+
64+
[headers.values]
65+
Strict-Transport-Security = "max-age=31536000"
66+
X-Test = 'foobar'
67+
```
68+
5669
## Next.js Middleware on Netlify
5770

5871
Next.js Middleware works out of the box on Netlify, but check out the

demos/default/netlify.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ CYPRESS_CACHE_FOLDER = "../node_modules/.CypressBinary"
1111
TERM = "xterm"
1212
NODE_VERSION = "16.15.1"
1313

14+
[[headers]]
15+
for = "/_next/image/*"
16+
17+
[headers.values]
18+
Strict-Transport-Security = "max-age=31536000"
19+
X-Test = 'foobar'
20+
1421
[dev]
1522
framework = "#static"
1623

package-lock.json

Lines changed: 51 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"@babel/preset-env": "^7.15.8",
4848
"@babel/preset-typescript": "^7.16.0",
4949
"@delucis/if-env": "^1.1.2",
50-
"@netlify/build": "^27.11.3",
50+
"@netlify/build": "^27.11.4",
5151
"@netlify/eslint-config-node": "^7.0.0",
5252
"@testing-library/cypress": "^8.0.1",
5353
"@types/fs-extra": "^9.0.13",

packages/runtime/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
"devDependencies": {
3030
"@delucis/if-env": "^1.1.2",
31-
"@netlify/build": "^27.11.3",
31+
"@netlify/build": "^27.11.4",
3232
"@types/fs-extra": "^9.0.13",
3333
"@types/jest": "^27.4.1",
3434
"@types/node": "^17.0.25",
@@ -62,4 +62,4 @@
6262
"engines": {
6363
"node": ">=12.0.0"
6464
}
65-
}
65+
}

packages/runtime/src/helpers/functions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ export const setupImageFunction = async ({
6060
netlifyConfig,
6161
basePath,
6262
remotePatterns,
63+
responseHeaders,
6364
}: {
6465
constants: NetlifyPluginConstants
6566
netlifyConfig: NetlifyConfig
6667
basePath: string
6768
imageconfig: Partial<ImageConfigComplete>
6869
remotePatterns: RemotePattern[]
70+
responseHeaders?: Record<string, string>
6971
}): Promise<void> => {
7072
const functionsPath = INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC
7173
const functionName = `${IMAGE_FUNCTION_NAME}.js`
@@ -76,6 +78,7 @@ export const setupImageFunction = async ({
7678
...imageconfig,
7779
basePath: [basePath, IMAGE_FUNCTION_NAME].join('/'),
7880
remotePatterns,
81+
responseHeaders,
7982
})
8083
await copyFile(join(__dirname, '..', '..', 'lib', 'templates', 'ipx.js'), join(functionDirectory, functionName))
8184

0 commit comments

Comments
 (0)