diff --git a/packages/commonwealth/Procfile b/packages/commonwealth/Procfile index 6418bb737c4..8ab74703ffe 100644 --- a/packages/commonwealth/Procfile +++ b/packages/commonwealth/Procfile @@ -3,4 +3,4 @@ consumer: cd packages/commonwealth && node --import=extensionless/register --max evm-ce: cd packages/commonwealth && node --import=extensionless/register --max-old-space-size=$(../../scripts/get-max-old-space-size.sh) build/server/workers/evmChainEvents/startEvmPolling.js knock: cd packages/commonwealth && node --import=extensionless/register --max-old-space-size=$(../../scripts/get-max-old-space-size.sh) build/server/workers/knock/knockWorker.js message-relayer: cd packages/commonwealth && node --import=extensionless/register --max-old-space-size=$(../../scripts/get-max-old-space-size.sh) build/server/workers/messageRelayer/messageRelayer.js -release: cd packages/commonwealth && node --import=extensionless/register --max-old-space-size=$(../../scripts/get-max-old-space-size.sh) build/server/scripts/releasePhaseEnvCheck.js && npx sequelize-cli db:migrate --config server/sequelize.json +release: cd packages/commonwealth && node --import=extensionless/register --max-old-space-size=$(../../scripts/get-max-old-space-size.sh) build/server/scripts/releasePhaseEnvCheck.js && npx sequelize-cli db:migrate --config server/sequelize.json && node --import=extensionless/register build/server/scripts/purgeCloudflareCache.js diff --git a/packages/commonwealth/server/scripts/purgeCloudflareCache.ts b/packages/commonwealth/server/scripts/purgeCloudflareCache.ts new file mode 100644 index 00000000000..2c5cee7b4f5 --- /dev/null +++ b/packages/commonwealth/server/scripts/purgeCloudflareCache.ts @@ -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); + }); diff --git a/packages/discord-bot/tsconfig.build.json b/packages/discord-bot/tsconfig.build.json index c0d2fda505e..986eed0532e 100644 --- a/packages/discord-bot/tsconfig.build.json +++ b/packages/discord-bot/tsconfig.build.json @@ -4,7 +4,11 @@ "rootDir": ".", "outDir": "build" }, - "include": ["src", "scripts/releasePhaseEnvCheck.ts"], + "include": [ + "src", + "scripts/releasePhaseEnvCheck.ts", + "scripts/purgeCloudflareCache.ts" + ], "references": [ { "path": "../../libs/adapters/tsconfig.build.json" }, { "path": "../../libs/core/tsconfig.build.json" },