mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
a96a9f38ce
* #108 Add eslint-config-spt * #108 Ignore bundle.js file * #108 Change eslint ignore path to a glob file * Remove jshint and follow more of eslint rules
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
var logger = require('./logger');
|
|
var nconf = require('nconf');
|
|
var fs = require('fs');
|
|
var ini = require('ini');
|
|
var knex = require('knex');
|
|
|
|
function isTestEnv() {
|
|
return process.env.NODE_ENV === 'test';
|
|
}
|
|
|
|
function getDatabaseIniUrl() {
|
|
// Finn specific way of delivering env variables
|
|
var databaseini = nconf.argv().get('databaseini');
|
|
var config = ini.parse(fs.readFileSync(databaseini, 'utf-8'));
|
|
|
|
logger.info('unleash started with databaseini: ' + databaseini);
|
|
|
|
return config.DATABASE_URL;
|
|
}
|
|
|
|
function getTestDatabaseUrl() {
|
|
if (process.env.TEST_DATABASE_URL) {
|
|
logger.info('unleash started with TEST_DATABASE_URL');
|
|
return process.env.TEST_DATABASE_URL;
|
|
} else {
|
|
throw new Error('please set TEST_DATABASE_URL');
|
|
}
|
|
}
|
|
|
|
function getDatabaseUrl() {
|
|
if (process.env.DATABASE_URL) {
|
|
logger.info('unleash started with DATABASE_URL');
|
|
return process.env.DATABASE_URL;
|
|
} else if (nconf.argv().get('databaseini') !== undefined) {
|
|
return getDatabaseIniUrl();
|
|
}
|
|
|
|
throw new Error('please set DATABASE_URL or pass --databaseini');
|
|
}
|
|
|
|
function createDbPool() {
|
|
return knex({
|
|
client: 'pg',
|
|
connection: isTestEnv() ? getTestDatabaseUrl() : getDatabaseUrl(),
|
|
pool: { min: 2, max: 20 }
|
|
});
|
|
}
|
|
|
|
module.exports = createDbPool();
|