Skip to content

Commit a94e40f

Browse files
feat(storage-vercel-blob): threads cacheControlMaxAge through static handler (#8065)
## Description I'm facing a issue while trying to set a cache age for vercel blob storage plugin, this way I changed to accept and set as response the cache control. ### Before changes ![image](https://github.com/user-attachments/assets/b67ee1a0-f4af-4f1f-942a-2063ec2fa5a2) ![image](https://github.com/user-attachments/assets/a3a7bce7-70be-4c06-ade6-3708f47d524c) ### After changes ![image](https://github.com/user-attachments/assets/9085193a-ef2d-4fa0-9aae-6817fe97aae0) ![image](https://github.com/user-attachments/assets/69a44948-402d-423b-873b-026be39c7501) ### Using plugin ``` vercelBlobStorage({ enabled: true, // Optional, defaults to true // dev: Specify which collections should use Vercel Blob collections: { [Media.slug]: true, }, // dev:Token provided by Vercel once Blob storage is added to your Vercel project token: process.env.BLOB_READ_WRITE_TOKEN!, cacheControlMaxAge: 31536000, /// the same we see }), ``` <!-- Please include a summary of the pull request and any related issues it fixes. Please also include relevant motivation and context. --> - [x] I have read and understand the [CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md) document in this repository. ## Type of change <!-- Please delete options that are not relevant. --> - [ ] Chore (non-breaking change which does not add functionality) - [x] 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) - [ ] Change to the [templates](https://github.com/payloadcms/payload/tree/main/templates) directory (does not affect core functionality) - [ ] Change to the [examples](https://github.com/payloadcms/payload/tree/main/examples) directory (does not affect core functionality) - [ ] This change requires a documentation update ## Checklist: - [ ] I have added tests that prove my fix is effective or that my feature works - [x] Existing test suite passes locally with my changes - [ ] I have made corresponding changes to the documentation
1 parent 2d29b7e commit a94e40f

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

packages/storage-vercel-blob/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function vercelBlobStorageInternal(
148148
prefix,
149149
token,
150150
}),
151-
staticHandler: getStaticHandler({ baseUrl, token }, collection),
151+
staticHandler: getStaticHandler({ baseUrl, token, cacheControlMaxAge }, collection),
152152
}
153153
}
154154
}

packages/storage-vercel-blob/src/staticHandler.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import path from 'path'
88
type StaticHandlerArgs = {
99
baseUrl: string
1010
token: string
11+
cacheControlMaxAge?: number
1112
}
1213

1314
export const getStaticHandler = (
14-
{ baseUrl, token }: StaticHandlerArgs,
15+
{ baseUrl, token, cacheControlMaxAge = 0 }: StaticHandlerArgs,
1516
collection: CollectionConfig,
1617
): StaticHandler => {
1718
return async (req, { params: { filename } }) => {
@@ -40,6 +41,7 @@ export const getStaticHandler = (
4041
'Content-Disposition': contentDisposition,
4142
'Content-Length': String(size),
4243
'Content-Type': contentType,
44+
'Cache-Control': `public, max-age=${cacheControlMaxAge}`
4345
}),
4446
status: 200,
4547
})

0 commit comments

Comments
 (0)