Skip to content

Instantly share code, notes, and snippets.

@beckyconning
Created May 8, 2014 21:58
Show Gist options
  • Save beckyconning/165c65c28ef722dce157 to your computer and use it in GitHub Desktop.
Save beckyconning/165c65c28ef722dce157 to your computer and use it in GitHub Desktop.
#!/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