@@ -260,13 +260,15 @@ export class CdnStack {
260
260
protocolPolicy : cloudfront . OriginProtocolPolicy . HTTPS_ONLY ,
261
261
} )
262
262
263
+ const apiCachePolicy = this . setApiCachePolicy ( scope )
264
+
263
265
return {
264
266
'/api' : {
265
267
origin,
266
268
compress : true ,
267
269
allowedMethods : cloudfront . AllowedMethods . ALLOW_ALL ,
268
270
cachedMethods : cloudfront . CachedMethods . CACHE_GET_HEAD_OPTIONS ,
269
- cachePolicy : this . setApiCachePolicy ( scope ) ,
271
+ cachePolicy : apiCachePolicy ,
270
272
viewerProtocolPolicy : cloudfront . ViewerProtocolPolicy . REDIRECT_TO_HTTPS ,
271
273
realtimeLogConfig : this . realtimeLogConfig ,
272
274
} ,
@@ -276,7 +278,7 @@ export class CdnStack {
276
278
compress : true ,
277
279
allowedMethods : cloudfront . AllowedMethods . ALLOW_ALL ,
278
280
cachedMethods : cloudfront . CachedMethods . CACHE_GET_HEAD_OPTIONS ,
279
- cachePolicy : this . apiCachePolicy ,
281
+ cachePolicy : apiCachePolicy ,
280
282
viewerProtocolPolicy : cloudfront . ViewerProtocolPolicy . REDIRECT_TO_HTTPS ,
281
283
realtimeLogConfig : this . realtimeLogConfig ,
282
284
} ,
@@ -514,7 +516,10 @@ export class CdnStack {
514
516
]
515
517
keysToRemove . forEach ( ( key ) => delete env [ key as EnvKey ] )
516
518
517
- behaviorOptions = this . apiBehaviorOptions ( scope , props )
519
+ behaviorOptions = {
520
+ ...this . apiBehaviorOptions ( scope , props ) ,
521
+ ...behaviorOptions ,
522
+ }
518
523
}
519
524
520
525
// if docMode is used, we don't need to add a behavior for the docs
@@ -549,15 +554,16 @@ export class CdnStack {
549
554
550
555
this . apiCachePolicy = new cloudfront . CachePolicy ( scope , 'ApiCachePolicy' , {
551
556
comment : 'Stacks API Cache Policy' ,
552
- cachePolicyName : `${ this . props . slug } -${ this . props . appEnv } -api-cache-policy` ,
557
+ cachePolicyName : `${ this . props . slug } -${ this . props . appEnv } -api-cache-policy- ${ this . props . timestamp } ` ,
553
558
defaultTtl : Duration . seconds ( 0 ) ,
554
559
minTtl : Duration . seconds ( 0 ) ,
555
- maxTtl : Duration . seconds ( 0 ) ,
560
+ maxTtl : Duration . seconds ( 1 ) , // Changed from 0 to 1 second
556
561
557
- // minTtl: config.cloud.cdn?.minTtl ? Duration.seconds(config.cloud.cdn.minTtl) : undefined,
558
562
cookieBehavior : cloudfront . CacheCookieBehavior . all ( ) ,
559
563
headerBehavior : cloudfront . CacheHeaderBehavior . allowList ( 'Authorization' , 'Content-Type' ) ,
560
564
queryStringBehavior : cloudfront . CacheQueryStringBehavior . all ( ) ,
565
+ enableAcceptEncodingGzip : true , // Added this line
566
+ enableAcceptEncodingBrotli : true , // Added this line
561
567
} )
562
568
563
569
return this . apiCachePolicy
0 commit comments