This PR makes it so that `modifyResponseHeaders` is supported in our
adapters when set on the collection config. Previously it would be
ignored.
This means that users can now modify or append new headers to what's
returned by each service.
```ts
import type { CollectionConfig } from 'payload'
export const Media: CollectionConfig = {
slug: 'media',
upload: {
modifyResponseHeaders: ({ headers }) => {
const newHeaders = new Headers(headers) // Copy existing headers
newHeaders.set('X-Frame-Options', 'DENY') // Set new header
return newHeaders
},
},
}
```
Also adds support for `void` return on the `modifyResponseHeaders`
function in the case where the user just wants to use existing headers
and doesn't need more control.
eg:
```ts
import type { CollectionConfig } from 'payload'
export const Media: CollectionConfig = {
slug: 'media',
upload: {
modifyResponseHeaders: ({ headers }) => {
headers.set('X-Frame-Options', 'DENY') // You can directly set headers without returning
},
},
}
```
Manual testing checklist (no CI e2es setup for these envs yet):
- [x] GCS
- [x] S3
- [x] Azure
- [x] UploadThing
- [x] Vercel Blob
---------
Co-authored-by: James <james@trbl.design>
38 lines
686 B
TypeScript
38 lines
686 B
TypeScript
import type { CollectionConfig } from 'payload'
|
|
|
|
export const Media: CollectionConfig = {
|
|
slug: 'media',
|
|
upload: {
|
|
modifyResponseHeaders({ headers }) {
|
|
headers.set('X-Universal-Truth', 'Set')
|
|
},
|
|
disableLocalStorage: true,
|
|
resizeOptions: {
|
|
position: 'center',
|
|
width: 200,
|
|
height: 200,
|
|
},
|
|
imageSizes: [
|
|
{
|
|
height: 400,
|
|
width: 400,
|
|
crop: 'center',
|
|
name: 'square',
|
|
},
|
|
{
|
|
width: 900,
|
|
height: 450,
|
|
crop: 'center',
|
|
name: 'sixteenByNineMedium',
|
|
},
|
|
],
|
|
},
|
|
fields: [
|
|
{
|
|
name: 'alt',
|
|
label: 'Alt Text',
|
|
type: 'text',
|
|
},
|
|
],
|
|
}
|