Skip to content

Commit 08af686

Browse files
committed
fix: purge CF edge cache on deploy + no-store on index.html
1 parent 0a09ce0 commit 08af686

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

worker/deploy-site.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,34 @@ async function main() {
7878
process.chdir(__dirname)
7979
exec('wrangler deploy')
8080

81+
// Purge Cloudflare cache for index.html
82+
log('\nStep 3: Purging cache...')
83+
const accountId = process.env.CLOUDFLARE_ACCOUNT_ID
84+
const apiToken = process.env.CLOUDFLARE_API_TOKEN
85+
if (accountId && apiToken) {
86+
try {
87+
// Get zone ID for commit451.com
88+
const zonesRaw = exec(
89+
`curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=commit451.com" ` +
90+
`-H "Authorization: Bearer ${apiToken}" -H "Content-Type: application/json"`
91+
)
92+
const zones = JSON.parse(zonesRaw)
93+
if (zones.result?.[0]?.id) {
94+
const zoneId = zones.result[0].id
95+
exec(
96+
`curl -s -X POST "https://api.cloudflare.com/client/v4/zones/${zoneId}/purge_cache" ` +
97+
`-H "Authorization: Bearer ${apiToken}" -H "Content-Type: application/json" ` +
98+
`-d '{"files":["https://castdrop.commit451.com/","https://castdrop.commit451.com/index.html"]}'`
99+
)
100+
log('Cache purged for index.html')
101+
} else {
102+
log('Warning: Could not find zone ID, skipping cache purge')
103+
}
104+
} catch {
105+
log('Warning: Cache purge failed (non-fatal)')
106+
}
107+
}
108+
81109
log('\n=== Deployment Complete ===')
82110
}
83111

worker/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,9 @@ async function serveSiteFile(env: Env, path: string): Promise<Response> {
261261
headers: {
262262
'Content-Type': getContentType(key),
263263
'Cache-Control': key === 'index.html'
264-
? 'no-cache'
264+
? 'no-store, no-cache, must-revalidate'
265265
: 'public, max-age=31536000, immutable',
266+
...(key === 'index.html' ? { 'CDN-Cache-Control': 'no-store' } : {}),
266267
},
267268
})
268269
}

0 commit comments

Comments
 (0)