File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
packages/open-next/src/overrides/cdnInvalidation Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ import {
2+ CloudFrontClient ,
3+ CreateInvalidationCommand ,
4+ } from "@aws-sdk/client-cloudfront" ;
5+ import type { CDNInvalidationHandler } from "types/overrides" ;
6+
7+ const cloudfront = new CloudFrontClient ( { } ) ;
8+ export default {
9+ name : "cloudfront" ,
10+ invalidatePaths : async ( paths ) => {
11+ //TODO: test the constructed paths
12+ const constructedPaths = paths . flatMap ( ( { path, isAppRouter } ) =>
13+ isAppRouter
14+ ? [ `${ path } ` , `${ path } ?_rsc=*` ]
15+ : [
16+ `${ path } ` ,
17+ `_next/data/${ process . env . BUILD_ID } ${ path === "/" ? "/index" : path } .json*` ,
18+ ] ,
19+ ) ;
20+ await cloudfront . send (
21+ new CreateInvalidationCommand ( {
22+ DistributionId : process . env . CLOUDFRONT_DISTRIBUTION_ID ! ,
23+ InvalidationBatch : {
24+ // Do we need to limit the number of paths? Or batch them into multiple commands?
25+ Paths : { Quantity : constructedPaths . length , Items : constructedPaths } ,
26+ CallerReference : `${ Date . now ( ) } ` ,
27+ } ,
28+ } ) ,
29+ ) ;
30+ } ,
31+ } satisfies CDNInvalidationHandler ;
You can’t perform that action at this time.
0 commit comments