From b76b4d20930878b3d23e62b5591ee41002920746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Thu, 23 Oct 2014 10:05:56 +0200 Subject: [PATCH] #18 reading db-config from DATABASE_URL or ini-file --- unleash-server/lib/dbPool.js | 16 +++++++++------- unleash-server/lib/eventStore.js | 1 + unleash-server/package.json | 1 + 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/unleash-server/lib/dbPool.js b/unleash-server/lib/dbPool.js index a2e2c2f4bc..1954866046 100644 --- a/unleash-server/lib/dbPool.js +++ b/unleash-server/lib/dbPool.js @@ -6,17 +6,19 @@ var anyDB = require('any-db'), function createDbPool() { - if (nconf.argv().get('databaseini') !== undefined) { + // Use postgres db from DATABASE_URL if set + if (process.env.DATABASE_URL) { + logger.info('unleash started with DATABASE_URL'); + return anyDB.createPool(process.env.DATABASE_URL); + } + + // Finn specific way of delivering env variables + else if(nconf.argv().get('databaseini') !== undefined) { var databaseini = nconf.argv().get('databaseini'); - logger.info('unleash started with databaseini: ' + databaseini); - var config = ini.parse(fs.readFileSync(databaseini, 'utf-8')); - return anyDB.createPool(config.DATABASE_URL, {min: 2, max: 20}); } } -module.exports = { - pool: createDbPool() -}; \ No newline at end of file +module.exports = createDbPool(); \ No newline at end of file diff --git a/unleash-server/lib/eventStore.js b/unleash-server/lib/eventStore.js index eaf873a682..a0cecaef70 100644 --- a/unleash-server/lib/eventStore.js +++ b/unleash-server/lib/eventStore.js @@ -1,5 +1,6 @@ var Promise = require('bluebird'), util = require('util'), + dbPool = require('./dbPool'), EventEmitter = require('events').EventEmitter; function EventStore() { diff --git a/unleash-server/package.json b/unleash-server/package.json index 5efd66056e..68bffe570f 100644 --- a/unleash-server/package.json +++ b/unleash-server/package.json @@ -40,6 +40,7 @@ "nconf": "0.6.9", "pg": "^3.6.1", "any-db": "2.1.0", + "any-db-pool": "2.1.0", "any-db-postgres": "2.1.3" }, "devDependencies": {