@@ -126,6 +126,49 @@ function main(callback) {
126
126
configureLocalBlogs ( ) ;
127
127
callback ( ) ;
128
128
} ,
129
+
130
+ // This is neccessary because when we deploy new dashboard or site code
131
+ // the old container will continue to serve the old code until they are
132
+ // replaced. So once the new code is deployed, we need to purge the CDN
133
+ // at the end of each setup.
134
+ async function ( ) {
135
+ if ( ! config . bunny . secret ) return ;
136
+
137
+ if ( config . environment !== "production" ) return ;
138
+
139
+ try {
140
+ const cdnURL = require ( "documentation/tools/cdn-url-helper" ) ( {
141
+ cacheID : new Date ( ) . getTime ( ) ,
142
+ viewDirectory : config . views_directory ,
143
+ } ) ( ) ;
144
+
145
+ const urls = [
146
+ "/dashboard.min.css" ,
147
+ "/dashboard.min.js" ,
148
+ "/documentation.min.css" ,
149
+ "/documentation.min.js" ,
150
+ ]
151
+ . map ( ( path ) => cdnURL ( path , ( p ) => p ) )
152
+ . map ( ( p ) => encodeURIComponent ( p ) ) ;
153
+
154
+ for ( const urlToPurge of urls ) {
155
+ const url = `https://api.bunny.net/purge?url=${ urlToPurge } &async=false` ;
156
+ const options = {
157
+ method : "POST" ,
158
+ headers : { AccessKey : config . bunny . secret } ,
159
+ } ;
160
+ console . log ( "Purging Bunny CDN cache" , url ) ;
161
+ const res = await fetch ( url , options ) ;
162
+ if ( res . status !== 200 ) {
163
+ console . error ( "Failed to purge Bunny CDN cache" , res . status ) ;
164
+ } else {
165
+ console . log ( "Purged Bunny CDN cache" , res . status ) ;
166
+ }
167
+ }
168
+ } catch ( e ) {
169
+ console . error ( "Failed to run function to purge Bunny CDN cache" , e ) ;
170
+ }
171
+ } ,
129
172
] ,
130
173
callback
131
174
) ;
0 commit comments