Skip to content

Instantly share code, notes, and snippets.

@hadifarnoud
Forked from fouad/cloudflare.json
Last active April 30, 2017 10:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hadifarnoud/dce196576c7d4ac26db1bb95e1a4e9a4 to your computer and use it in GitHub Desktop.
Save hadifarnoud/dce196576c7d4ac26db1bb95e1a4e9a4 to your computer and use it in GitHub Desktop.
Purge CloudFlare cache on deploy
{
"email": "me@email.com",
"zone": "CLOUDFLARE_ZONE",
"token": "CLOUDFLARE_TOKEN"
}
curl -X GET "https://api.cloudflare.com/client/v4/zones" \
-H "X-Auth-Email: user@example.com" \
-H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
-H "Content-Type: application/json"
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: {
"files":["http://cdn.mykamva.ir/optimised.js"],
},
json: true
}, function (err, response, body) {
if (err) {
throw err
}
console.log('CloudFlare cache purge response')
console.log(body)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment