Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #45 from Financial-Times/purge
Browse files Browse the repository at this point in the history
Purge
  • Loading branch information
aintgoin2goa committed Apr 8, 2015
2 parents 1d664bb + ec12f99 commit 2722087
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/node_modules/
.idea/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
deploy-hashed-assets deploys hashed asset files to S3 (if AWS keys set correctly)
build build javascript and css
destroy [app] deletes the app from heroku
purge [options] purges the given url from the Fastly cache. Requires a FASTLY_KEY environment variable set to your fastly api key
*

Options:
Expand Down
15 changes: 15 additions & 0 deletions bin/next-build-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var verify = require('../tasks/verify');
var build = require('../tasks/build');
var verifyLayoutDeps = require('../tasks/verify-layout-deps');
var destroy = require('../tasks/destroy');
var purge = require('../tasks/purge');
var nightwatch = require('../tasks/nightwatch');
var downloadConfiguration = require('../tasks/download-configuration');
var deployHashedAssets = require('../tasks/deploy-hashed-assets');
Expand Down Expand Up @@ -129,13 +130,27 @@ program
}
});

program
.command('purge [url')
.option('-s, --soft <soft>', 'Perform a "Soft Purge (will invalidate the content rather than remove it"')
.description('Purges the given url. Requires a FASTLY_KEY environment variable')
.action(function(url, options){
if(url){
purge(url, options).catch(exit);
}else{
exit('Please provide a url');
}
});

program
.command('*')
.description('')
.action(function(app) {
exit("The command ‘" + app + "’ is not known");
});



program.parse(process.argv);

if (!process.argv.slice(2).length) {
Expand Down
29 changes: 29 additions & 0 deletions tasks/purge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

var denodeify = require('denodeify');
var exec = denodeify(require('child_process').exec, function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
return [err];
});

var FASTLY_KEY = process.env.FASTLY_KEY;

module.exports = function(url, opts){
if(!FASTLY_KEY){
throw new Error('No Fastly Key Found!');
}

var options = opts || {};
var soft = options.soft || false;
var command = 'curl ' +
'-x 10.113.219.30:8080 ' +
'-s 1 ' +
'-i ' +
'--request PURGE ' +
'--header "Fastly-Key: ' + FASTLY_KEY + '" ' +
'--header "Content-Accept: application/json" ' +
(soft ? '--header "Fastly-Soft-Purge:1' : '') +
url;
return exec(command);
};

0 comments on commit 2722087

Please sign in to comment.