-
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 00a9dc9
Showing
3 changed files
with
39 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
33 changes: 33 additions & 0 deletions
33
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,33 @@ | ||
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); | ||
Check failure on line 33 in packages/commonwealth/server/scripts/purgeCloudflareCache.ts GitHub Actions / Code Quality checks (20)
|
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