Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,26 +147,36 @@ myNextApplication:
]
# this is the cache behaviour for next.js api pages
api:
ttl: 10
minTTL: 10
maxTTL: 10
defaultTTL: 10
# you can set other cache behaviours like "defaults" above that can handle server side rendering
# but more specific for a subset of your next.js pages
/blog/*:
ttl: 1000
minTTL: 1000
maxTTL: 1000
defaultTTL: 1000
forward:
cookies: "all"
queryString: false
/about:
ttl: 3000
minTTL: 3000
maxTTL: 3000
defaultTTL: 3000
# you can add custom origins to the cloudfront distribution
origins:
- url: /static
pathPatterns:
/wp-content/*:
ttl: 10
minTTL: 10
maxTTL: 10
defaultTTL: 10
- url: https://old-static.com
pathPatterns:
/old-static/*:
ttl: 10
minTTL: 10
maxTTL: 10
defaultTTL: 10
priceClass: "PriceClass_100"
```

Expand Down
3 changes: 2 additions & 1 deletion packages/libs/s3-static-assets/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ const uploadStaticAssets = async (
s3Key: pathToPosix(
withBasePath(prerenderManifest.routes[key].dataRoute.slice(1))
),
filePath: pageFilePath
filePath: pageFilePath,
cacheControl: SERVER_CACHE_CONTROL_HEADER
});
});

Expand Down
6 changes: 3 additions & 3 deletions packages/libs/s3-static-assets/tests/upload-assets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,23 @@ describe.each`
expect.objectContaining({
Key: "_next/data/zsWqBqLjpgRmswfQomanp/index.json",
ContentType: "application/json",
CacheControl: undefined
CacheControl: SERVER_CACHE_CONTROL_HEADER
})
);

expect(mockUpload).toBeCalledWith(
expect.objectContaining({
Key: "_next/data/zsWqBqLjpgRmswfQomanp/todos/terms/a.json",
ContentType: "application/json",
CacheControl: undefined
CacheControl: SERVER_CACHE_CONTROL_HEADER
})
);

expect(mockUpload).toBeCalledWith(
expect.objectContaining({
Key: "_next/data/zsWqBqLjpgRmswfQomanp/todos/terms/b.json",
ContentType: "application/json",
CacheControl: undefined
CacheControl: SERVER_CACHE_CONTROL_HEADER
})
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ describe("Input origin as a custom url", () => {
it("creates distribution with custom default behavior options", async () => {
await component.default({
defaults: {
ttl: 0,
minTTL: 0,
defaultTTL: 0,
maxTTL: 31536000,
forward: {
headers: ["Accept", "Accept-Language"],
cookies: "all",
Expand Down Expand Up @@ -53,14 +55,18 @@ describe("Input origin as a custom url", () => {
it("creates distribution with custom behavior options", async () => {
await component.default({
defaults: {
ttl: 0
minTTL: 0,
defaultTTL: 0,
maxTTL: 31536000
},
origins: [
{
url: "https://mycustomorigin.com",
pathPatterns: {
"/sample/path": {
ttl: 0,
minTTL: 0,
defaultTTL: 0,
maxTTL: 0,
forward: {
headers: "all",
cookies: ["auth-token"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ describe("Input origin as a custom url", () => {
"PUT",
"PATCH"
],
ttl: 10,
minTTL: 0,
defaultTTL: 10,
maxTTL: 31536000,
"lambda@edge": {
"origin-request":
"arn:aws:lambda:us-east-1:123:function:originRequestFunction"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ describe("Working with an existing distribution", () => {
url: "https://existingorigin2.com",
pathPatterns: {
"/some/path": {
ttl: 10
minTTL: 10,
defaultTTL: 10,
maxTTL: 10
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ describe("Input origin as a custom url", () => {
url: "https://exampleorigin.com",
pathPatterns: {
"/some/path": {
ttl: 10,
minTTL: 10,
defaultTTL: 10,
maxTTL: 10,
"lambda@edge": {
"viewer-request":
"arn:aws:lambda:us-east-1:123:function:viewerRequestFunction",
Expand Down Expand Up @@ -88,7 +90,9 @@ describe("Input origin as a custom url", () => {
url: "https://exampleorigin.com",
pathPatterns: {
"/some/path": {
ttl: 10,
minTTL: 10,
defaultTTL: 10,
maxTTL: 10,
"lambda@edge": {
"invalid-eventtype":
"arn:aws:lambda:us-east-1:123:function:viewerRequestFunction"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ describe("Input origin with path pattern", () => {
url: "https://exampleorigin.com",
pathPatterns: {
"/some/path": {
ttl: 10,
minTTL: 10,
defaultTTL: 10,
maxTTL: 10,
allowedHttpMethods: ["GET", "HEAD", "POST"]
}
}
Expand Down Expand Up @@ -78,7 +80,9 @@ describe("Input origin with path pattern", () => {
url: "https://exampleorigin.com",
pathPatterns: {
"/some/path": {
ttl: 10
minTTL: 10,
defaultTTL: 10,
maxTTL: 10
}
}
}
Expand All @@ -91,7 +95,9 @@ describe("Input origin with path pattern", () => {
url: "https://exampleorigin.com",
pathPatterns: {
"/some/other/path": {
ttl: 10
minTTL: 10,
defaultTTL: 10,
maxTTL: 10
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ const { getForwardedValues } = require("./cacheBahaviorUtils");
module.exports = (pathPattern, pathPatternConfig, originId) => {
const {
allowedHttpMethods = ["GET", "HEAD"],
ttl,
minTTL,
defaultTTL,
maxTTL,
compress = true,
smoothStreaming = false,
viewerProtocolPolicy = "https-only",
Expand All @@ -15,7 +17,7 @@ module.exports = (pathPattern, pathPatternConfig, originId) => {
cookies: "all",
queryString: true
}),
MinTTL: ttl,
MinTTL: minTTL,
PathPattern: pathPattern,
TargetOriginId: originId,
TrustedSigners: {
Expand All @@ -33,8 +35,8 @@ module.exports = (pathPattern, pathPatternConfig, originId) => {
},
Compress: compress,
SmoothStreaming: smoothStreaming,
DefaultTTL: ttl,
MaxTTL: ttl,
DefaultTTL: defaultTTL,
MaxTTL: maxTTL,
FieldLevelEncryptionId: fieldLevelEncryptionId,
LambdaFunctionAssociations: {
Quantity: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ module.exports = (originId, defaults = {}) => {
const {
allowedHttpMethods = ["HEAD", "GET"],
forward = {},
ttl = 86400,
minTTL = 0,
defaultTTL = 86400,
maxTTL = 31536000,
compress = false,
smoothStreaming = false,
viewerProtocolPolicy = "redirect-to-https",
Expand All @@ -21,7 +23,7 @@ module.exports = (originId, defaults = {}) => {
Items: []
},
ViewerProtocolPolicy: viewerProtocolPolicy,
MinTTL: 0,
MinTTL: minTTL,
AllowedMethods: {
Quantity: allowedHttpMethods.length,
Items: allowedHttpMethods,
Expand All @@ -31,8 +33,8 @@ module.exports = (originId, defaults = {}) => {
}
},
SmoothStreaming: smoothStreaming,
DefaultTTL: ttl,
MaxTTL: 31536000,
DefaultTTL: defaultTTL,
MaxTTL: maxTTL,
Compress: compress,
LambdaFunctionAssociations: {
Quantity: 0,
Expand Down
Loading