diff --git a/lib/web/handlers/api.js b/lib/web/handlers/api.js index e8190eb..0cd8c5b 100644 --- a/lib/web/handlers/api.js +++ b/lib/web/handlers/api.js @@ -78,33 +78,29 @@ exports.getAPIHandlers = function(dreadnot, authdb) { // view. function deploy(req, res) { var stackName = req.params.stack, - regionName = req.params.region, - to = req.body.to_revision, user; - - async.waterfall([ - dreadnot.deploy.bind(dreadnot, stackName, regionName, to, req.remoteUser.name), - - function(number, callback) { - dreadnot.getDeploymentSummary(stackName, regionName, number, callback); - } - ], res.respond); - } - - function getWarning(req, res) { - res.respond(null, {message: dreadnot.warning}); - } - - // Store the warning message - function saveWarning(req, res) { - var text = req.body.action === 'save' ? req.body.warning_text : ''; - - dreadnot.setWarning(req.remoteUser, text, function(err) { - if (err) { - res.respond(err); - } else { - getWarning(req, res); - } - }); + regionName = req.params.region, + to; + + function deploy() { + async.waterfall([ + dreadnot.deploy.bind(dreadnot, stackName, regionName, to, req.remoteUser.name), + + function(number, callback) { + dreadnot.getDeploymentSummary(stackName, regionName, number, callback); + } + ], res.respond); + } + + //Make the to_revision field optional + if (typeof req.body !== 'undefined' || typeof req.body.to_revision !== 'undefined') { + to = req.body.to_revision; + deploy(); + } else { + dreadnot.getStackSummary(req.params.stack, function(err, data) { + to = data["latest_revision"]; + deploy(); + }); + } } // Return bound handlers