Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit 0ee2f55

Browse files
committed
add Expires header to the regenerated S3 objects
1 parent 65ba637 commit 0ee2f55

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

packages/libs/lambda-at-edge/src/default-handler.ts

+3
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,9 @@ const handleOriginResponse = async ({
622622
? new Date(lastModifiedHeaderString)
623623
: null;
624624
if (typeof initialRevalidateSeconds === "number" && lastModifiedAt) {
625+
/**
626+
* TODO: Refactor to use the returned `Expired` header.
627+
*/
625628
const createdAgo =
626629
(Date.now() - (lastModifiedAt.getTime() || Date.now())) / 1000;
627630

packages/libs/lambda-at-edge/src/regeneration-handler.ts

+3
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,14 @@ export const handler: AWSLambda.SQSHandler = async (event) => {
5959
"passthrough"
6060
);
6161

62+
const expires = new Date(Date.now() + renderOpts.revalidate * 1000);
6263
const s3BasePath = basePath ? `${basePath.replace(/^\//, "")}/` : "";
6364
const s3JsonParams = {
6465
Bucket: bucketName,
6566
Key: `${s3BasePath}${jsonKey}`,
6667
Body: JSON.stringify(renderOpts.pageData),
6768
ContentType: "application/json",
69+
Expires: expires,
6870
CacheControl: "public, max-age=0, s-maxage=2678400, must-revalidate"
6971
};
7072

@@ -73,6 +75,7 @@ export const handler: AWSLambda.SQSHandler = async (event) => {
7375
Key: `${s3BasePath}${htmlKey}`,
7476
Body: html,
7577
ContentType: "text/html",
78+
Expires: expires,
7679
CacheControl: "public, max-age=0, s-maxage=2678400, must-revalidate"
7780
};
7881

0 commit comments

Comments
 (0)