refactor db connection string

This commit is contained in:
Josh Harvey 2016-06-12 13:19:00 +03:00
parent 944de6fab0
commit 91e0fed95d
9 changed files with 47 additions and 82 deletions

29
lib/options.js Normal file
View file

@ -0,0 +1,29 @@
'use strict'
var fs = require('fs')
var path = require('path')
var os = require('os')
var options
var configPath
try {
configPath = '/etc/lamassu.json'
options = JSON.parse(fs.readFileSync(configPath))
} catch (err) {
try {
configPath = path.resolve(os.homedir(), '.lamassu', 'lamassu.json')
options = JSON.parse(fs.readFileSync(configPath))
} catch (err2) {
console.log('Missing configuration file -- exiting.')
process.exit(1)
}
}
var psqlUrl = options.postgres
if (!psqlUrl) {
console.log('Missing postgres entry in configuration file: %s', configPath)
process.exit(2)
}
module.exports = options