-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added script to procfile to purge cloudflare cache on release
- Loading branch information
1 parent
624f913
commit 64cf7ba
Showing
3 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/commonwealth/server/scripts/purgeCloudflareCache.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { config } from 'dotenv'; | ||
import fetch from 'node-fetch'; | ||
|
||
config(); | ||
|
||
async function purgeCache(zoneId?: string, apiKey?: string) { | ||
if (!zoneId || !apiKey) throw Error('Missing Env Vars'); | ||
|
||
const url = `https://api.cloudflare.com/client/v4/zones/${zoneId}/purge_cache`; | ||
const body = { | ||
purge_everything: true, | ||
}; | ||
const headers = { | ||
Authorization: `Bearer ${apiKey}`, | ||
'Content-Type': 'application/json', | ||
}; | ||
|
||
try { | ||
const response = await fetch(url, { | ||
method: 'POST', | ||
headers: headers, | ||
body: JSON.stringify(body), | ||
}); | ||
|
||
const responseData = await response.json(); | ||
console.log('Cache purge request successful:'); | ||
console.log(responseData); | ||
} catch (error) { | ||
console.error('Error purging cache:', error.message); | ||
} | ||
} | ||
|
||
purgeCache(process.env.CF_ZONE_ID, process.env.CF_API_KEY) | ||
.then(() => console.log('finished cloudflare purge script')) | ||
.catch((e) => { | ||
console.log('cloudflare purge script failed:', e); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters