Created
May 3, 2016 23:23
-
-
Save sjwilliams/b3fc099ab9cfc3b4c06a377bffdb2f5e to your computer and use it in GitHub Desktop.
Purging Imgix CDN with node.js
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
var Curl = require( 'node-libcurl' ).Curl; | |
var querystring = require( 'querystring' ); | |
var IMGIX_API_KEY = ''; | |
function imgixPurge(url){ | |
var curl = new Curl(); | |
curl.setOpt(Curl.option.URL, 'https://api.imgix.com/v2/image/purger'); | |
curl.setOpt('HTTPAUTH', Curl.auth.BASIC); | |
curl.setOpt(Curl.option.USERNAME, IMGIX_API_KEY); | |
curl.setOpt(Curl.option.TIMEOUT, 20); | |
curl.setOpt(Curl.option.HTTPHEADER, ['User-Agent: node-libcurl/1.0']); | |
// curl.setOpt( Curl.option.VERBOSE, true ); | |
curl.setOpt(Curl.option.POSTFIELDS, querystring.stringify({'url': url})); | |
curl.perform(); | |
curl.on('error', curl.close.bind(curl)); | |
curl.on('end', function(statusCode, body, headers){ | |
if (statusCode === 200) { | |
console.log('success'); | |
} else { | |
console.log('something went wrong'); | |
} | |
curl.close(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment