Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.log('Configuration (change them with environment variables): ');
console.log('\tHOST: \t\t\t', HOST);
console.log('\tPORT: \t\t\t', PORT);
console.log('\tCOUCHDB_BASE_URL: \t', COUCHDB_BASE_URL);
console.log('\tCOUCHDB_DB_NAME: \t', COUCHDB_DB_NAME);
nano = nano(COUCHDB_BASE_URL);
if (!COUCHDB_BASE_URL) {
throw new Error('Environment variable COUCHDB_BASE_URL is not set!');
}
var server;
console.log('Destroying database ' + COUCHDB_DB_NAME);
Q.ninvoke(nano.db, 'destroy', COUCHDB_DB_NAME).
then(function() {}, function() {}).
then(function() {
console.log('Creating database ' + COUCHDB_DB_NAME);
return Q.ninvoke(nano.db, 'create', COUCHDB_DB_NAME);
}).then(function() {
var model = new couchDBModel(nano.use(COUCHDB_DB_NAME), {
restapi: {
index: true,
byID: true,
save: true
}
});
console.log('Bound REST API to request event');
server.on('request', model.onRequest);
process.on('SIGTERM', function() {
console.log('Destroying database ' + COCUDB_DB_NAME);
nano.db.destroy(COUCHDB_DB_NAME, function(error) {
if (error) {
throw error;
}
server.close();
console.log('Bye.');
});
});
ssl: process.env['COUCH_SSL'],
host: process.env['COUCH_HOST'],
port: process.env['COUCH_PORT'],
registry: (process.env['REGISTRY_DB_NAME'] || 'registry')
};
var sqsQueueName = process.env['QUEUE_NAME'];
var admin = { username: process.env['COUCH_USER'], password: process.env['COUCH_PASS'] };
var rootCouch = util.format('%s://%s:%s', (couch.ssl == 1) ? 'https': 'http', couch.host, couch.port) //https is optional so that we can play localy without SSL. That being said, in production it should be 1!
, rootCouchAdmin = util.format('%s://%s:%s@%s:%d', (couch.ssl == 1) ? 'https': 'http', admin.username, admin.password, couch.host, couch.port)
, rootCouchRegistry = util.format('%s://%s:%s/%s', (couch.ssl == 1) ? 'https': 'http', couch.host, couch.port, couch.registry);
var nano = require('nano')(rootCouchAdmin); //connect as admin
var registry = nano.db.use(couch.registry)
var sqs = new AWS.SQS();
s3.createBucket(function(err, data) {
if(err) throw err;
console.log('S3 bucket (%s) OK', bucket);
sqs.getQueueUrl({QueueName: sqsQueueName}, function(err, data){
if(err) throw err;
var queueUrl = data.QueueUrl;
if(!queueUrl.length) throw new Error('could not get queue');
console.log('queue "%s" at: %s', sqsQueueName, queueUrl);