mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-03-22 19:05:56 -04:00
Activate after configuring Fastly
This commit is contained in:
parent
f90adfcadb
commit
494085247d
2 changed files with 40 additions and 4 deletions
|
@ -90,9 +90,14 @@ async.auto({
|
|||
fastly.getLatestVersion(function (err, response) {
|
||||
if (err) return cb(err);
|
||||
// Validate latest version before continuing
|
||||
if (response.active) return cb('Latest version is active. Will not modify.');
|
||||
if (response.locked) return cb('Latest version is locked. Cannot modify.');
|
||||
cb(null, response.number);
|
||||
if (response.active || response.locked) {
|
||||
fastly.cloneVersion(response.number, function (err, response) {
|
||||
if (err) return cb('Failed to clone latest version: ' + err);
|
||||
cb(null, response.number);
|
||||
});
|
||||
} else {
|
||||
cb(null, response.number);
|
||||
}
|
||||
});
|
||||
},
|
||||
notPassRequestCondition: ['version', function (cb, results) {
|
||||
|
@ -200,7 +205,13 @@ async.auto({
|
|||
cb(null, headers);
|
||||
});
|
||||
}]},
|
||||
function (err) {
|
||||
function (err, results) {
|
||||
if (err) throw new Error(err);
|
||||
if (process.env.FASTLY_ACTIVATE_CHANGES) {
|
||||
fastly.activateVersion(results.version, function (err, response) {
|
||||
if (err) throw new Error(err);
|
||||
process.stdout.write('Successfully configured and activated version ' + response.number + '\n');
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
@ -109,5 +109,30 @@ module.exports = function (apiKey, serviceId) {
|
|||
return cb(null, response);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
/*
|
||||
* cloneVersion: Clone a version to create a new version
|
||||
*
|
||||
* @param {number} Version to clone
|
||||
* @param {callback} Callback for fastly.request
|
||||
*/
|
||||
fastly.cloneVersion = function (version, cb) {
|
||||
if (!this.serviceId) return cb('Failed to clone version. No serviceId configured.');
|
||||
var url = this.getFastlyAPIPrefix(this.serviceId, version) + '/clone';
|
||||
this.request('PUT', url, cb);
|
||||
};
|
||||
|
||||
/*
|
||||
* activateVersion: Activate a version
|
||||
*
|
||||
* @param {number} Version number
|
||||
* @param {callback} Callback for fastly.request
|
||||
*/
|
||||
fastly.activateVersion = function (version, cb) {
|
||||
if (!this.serviceId) return cb('Failed to activate version. No serviceId configured.');
|
||||
var url = this.getFastlyAPIPrefix(this.serviceId, version) + '/activate';
|
||||
this.request('PUT', url, cb);
|
||||
};
|
||||
|
||||
return fastly;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue