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

Commit 7480a86

Browse files
committed
🐛 fix(caching): properly set API caching as previous syntax was not working
1 parent 92540fb commit 7480a86

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

Diff for: lib/cdk/utils/cfnDistro.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { CfnOutput, Duration, Stack } from 'aws-cdk-lib'
33
import { ICertificate } from 'aws-cdk-lib/aws-certificatemanager'
44
import {
55
AllowedMethods,
6+
BehaviorOptions,
67
CacheCookieBehavior,
78
CacheHeaderBehavior,
89
CachePolicy,
10+
CachePolicyProps,
911
CacheQueryStringBehavior,
1012
Distribution,
1113
IOrigin,
@@ -37,12 +39,12 @@ export const setupCfnDistro = (
3739
const imageOrigin = new HttpOrigin(apiGwDomainName, { originPath: imageBasePath })
3840
const assetsOrigin = new S3Origin(assetsBucket)
3941

40-
const defaultOptions = {
42+
const defaultOptions: Partial<BehaviorOptions> = {
4143
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
4244
allowedMethods: AllowedMethods.ALLOW_GET_HEAD_OPTIONS,
4345
}
4446

45-
const defaultCacheOptions = {
47+
const defaultCacheOptions: Partial<CachePolicyProps> = {
4648
headerBehavior: CacheHeaderBehavior.allowList('accept', 'accept-language', 'content-language', 'content-type', 'user-agent', 'authorization'),
4749
queryStringBehavior: CacheQueryStringBehavior.all(),
4850
cookieBehavior: CacheCookieBehavior.all(),
@@ -58,12 +60,6 @@ export const setupCfnDistro = (
5860
...defaultCacheOptions,
5961
})
6062

61-
const apiCachePolicy = new CachePolicy(scope, 'NextApiCachePolicy', {
62-
...defaultCacheOptions,
63-
maxTtl: Duration.seconds(0),
64-
defaultTtl: Duration.seconds(0),
65-
})
66-
6763
// Public folder persists names so we are making default TTL lower for cases when invalidation does not happen.
6864
const assetsCachePolicy = new CachePolicy(scope, 'NextPublicCachePolicy', {
6965
queryStringBehavior: CacheQueryStringBehavior.all(),
@@ -91,7 +87,7 @@ export const setupCfnDistro = (
9187
...defaultOptions,
9288
origin: customApiOrigin ?? serverOrigin,
9389
allowedMethods: AllowedMethods.ALLOW_ALL,
94-
cachePolicy: apiCachePolicy,
90+
cachePolicy: CachePolicy.CACHING_DISABLED,
9591
},
9692
'_next/data/*': {
9793
...defaultOptions,

0 commit comments

Comments
 (0)