Skip to content

Instantly share code, notes, and snippets.

@sjwilliams
Created May 3, 2016 23:23
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 sjwilliams/b3fc099ab9cfc3b4c06a377bffdb2f5e to your computer and use it in GitHub Desktop.
Save sjwilliams/b3fc099ab9cfc3b4c06a377bffdb2f5e to your computer and use it in GitHub Desktop.
Purging Imgix CDN with node.js
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