azure-cdn
Deploy static assets to azure blob storage for consumption via cdn.
var uploadToAzure = require('azure-cdn');
uploadToAzure({
blobService: [ ... ],
container: null,
containerOptions: {publicAccessLevel: 'blob'},
folder: '',
metadata: {cacheControl: 'public, max-age=31556926'},
concurrency: 10
erase: true,
zip: true,
test: true,
log: function () {},
files: [
{ cwd: './public',
path: '/user/test/project/public/index.html' }
...
]
})
.then(function () { ... })
.catch(function (error) { ... });
Grunt
An example grunt task. Where files are provided by the src
field in grunt options
var upload = require('azure-cdn');
var path = require('path');
module.exports = function (grunt) {
grunt.registerMultiTask('azure-cdn', 'Copy files to an azure storage blob', function () {
var asyncTask = this.async();
var options = this.options();
options.log = grunt.log.debug;
options.files = Array.prototype.concat.apply([], this.files.map(function (glob) {
return glob.src.map(function (file) {
return {path: path.resolve(glob.cwd, file), cwd: glob.cwd};
});
}));
upload(options).then(asyncTask)
.catch(function (err) {
grunt.log.error('Error while copying files to azure ' + err);
asyncTask(false);
});
});
};