Skip to content

Instantly share code, notes, and snippets.

@fouad
Created October 12, 2015 06:42
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fouad/a80f17b34698eebd856c to your computer and use it in GitHub Desktop.
Save fouad/a80f17b34698eebd856c to your computer and use it in GitHub Desktop.
Purge CloudFlare cache on deploy
{
"email": "me@email.com",
"zone": "CLOUDFLARE_ZONE",
"token": "CLOUDFLARE_TOKEN"
}
var gulp = require('gulp')
var request = require('request')
gulp.task('purge-cache', function () {
var cf = require('./cloudflare.json')
request({
url: 'https://api.cloudflare.com/client/v4/zones/' + cf.zone + '/purge_cache',
method: 'DELETE',
headers: {
'X-AUTH-EMAIL': cf.email,
'X-Auth-Key': cf.token,
'Content-Type': 'application/json'
},
body: {
purge_everything: true
},
json: true
}, function (err, response, body) {
if (err) {
throw err
}
console.log('CloudFlare cache purge response')
console.log(body)
})
})
@alvarotrigo
Copy link

Nice, thanks for that! :)
Btw, I had to use the Global API instead of a new Token, didn't work otherwise not sure why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment