-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deployment: set cache headers (#1036)
- Loading branch information
1 parent
984eb64
commit c57063f
Showing
4 changed files
with
54 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
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,49 @@ | ||
#!/usr/bin/env node | ||
/* global process */ | ||
|
||
// This script runs just before the app starts. If we are running the | ||
// production heroku app (the only one with the below env variables) | ||
// the cache gets cleared. | ||
// | ||
// To clear the cache yourself, you can use the button in the | ||
// cloudflare dashboard ("Caching tab > Purge everything"), or run | ||
// this script with the required environment variables: | ||
// | ||
// - CLOUDFLARE_TOKEN: a token with the "Zone.Cache Purge" permission. | ||
// You can generate this token in "My Profile > API Tokens" | ||
// | ||
// - CLOUDFLARE_ZONE_ID: The zone ID to purge. You can find it in the | ||
// sidebar of the "overview" tab for dvc.org | ||
|
||
const fetch = require('isomorphic-fetch'); | ||
|
||
const { CLOUDFLARE_TOKEN, CLOUDFLARE_ZONE_ID } = process.env; | ||
|
||
async function main() { | ||
const res = await fetch( | ||
`https://api.cloudflare.com/client/v4/zones/${CLOUDFLARE_ZONE_ID}/purge_cache`, | ||
{ | ||
method: 'POST', | ||
headers: { | ||
authorization: `Bearer ${CLOUDFLARE_TOKEN}`, | ||
'content-type': 'application/json' | ||
}, | ||
body: JSON.stringify({ purge_everything: true }) | ||
} | ||
); | ||
|
||
const body = await res.text(); | ||
|
||
if (!res.ok) { | ||
throw new Error('Error response received from CloudFlare: ' + body); | ||
} | ||
|
||
console.log('Cleared cache successfully'); | ||
} | ||
|
||
if (CLOUDFLARE_TOKEN) { | ||
main().catch(e => { | ||
console.error(e); | ||
process.exit(1); | ||
}); | ||
} |
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
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