Created
May 8, 2014 21:58
-
-
Save beckyconning/165c65c28ef722dce157 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var requestPromise = require('request-promise'); | |
var couchUrl = process.argv[2]; | |
var configureCouch = function(couchUrl, requestPromise) { | |
var couchConfigUrl = couchUrl + '/_config'; | |
var couchConfig = { | |
httpd: { | |
enable_cors: 'true' | |
}, | |
cors: { | |
origins: '*', | |
credentials: 'true' | |
} | |
}; | |
Object.keys(couchConfig).forEach(function(sectionKey) { | |
var section = couchConfig[sectionKey]; | |
Object.keys(section).forEach(function(optionKey) { | |
var option = section[optionKey]; | |
var url = couchConfigUrl + '/' + sectionKey + '/' + optionKey; | |
var options = { | |
url: url, | |
method: 'PUT', | |
json: true, | |
body: JSON.stringify(option) | |
}; | |
var configurationOptionPutRequest = requestPromise(options); | |
configurationOptionPutRequest.then(function(responseBody) { | |
console.log( | |
'Changed ' + sectionKey + ' -> ' + optionKey + | |
' from ' + responseBody + ' to ' + option | |
); | |
}, console.error); | |
}); | |
}); | |
}; | |
var createDatabases = function(couchUrl) { | |
var namesOfDatabasesToCreate = ['presentations']; | |
namesOfDatabasesToCreate.forEach(function(databaseName) { | |
var databaseUrl = couchUrl + '/' + databaseName; | |
var options = { | |
url: databaseUrl, | |
method: 'PUT' | |
}; | |
var databaseCreationRequest = requestPromise(options); | |
databaseCreationRequest.then(function() { | |
console.log('Created database \'' + databaseName + '\''); | |
}, console.error); | |
}); | |
}; | |
if (typeof couchUrl !== 'undefined') { | |
configureCouch(couchUrl); | |
createDatabases(couchUrl); | |
} | |
else { | |
console.log('Usage: couch-init http://couchUrl'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment