var fs = require('fs'); var bunyan = require('bunyan'); function isProd() { return process.env.NODE_ENV == 'prod'; } var mqttUrl = process.env.MQTT_URL || 'mqtt://trygvis.io'; var postgresqlConfig = { host: process.env.DB_HOST || '/var/run/postgresql', database: process.env.DB_DATABASE || 'diller', user: process.env.DB_USER || 'diller', password: process.env.DB_PASSWORD || 'diller' }; var log; function configureLogging(app) { if (log) { return; } var cfg = { name: app }; if (isProd()) { cfg.streams = [ { level: 'warn', stream: process.stdout }, { level: 'debug', path: 'log/diller-' + app + '.log' } ]; var stat; try { stat = fs.lstatSync('log'); } catch (e) { // Assume this to to be ENOENT fs.mkdirSync('log'); } if (stat && !stat.isDirectory()) { throw 'Not a directory: log'; } } log = bunyan.createLogger(cfg); } /** * @constructor */ function DillerConfig() { var httpPort = process.env.HTTP_PORT || 8080; /** * @lends DillerConfig.prototype */ return { isProd: isProd, updateDillerRpc: !isProd(), mqttUrl: mqttUrl, postgresqlConfig: postgresqlConfig, httpPort: httpPort, configureLogging: configureLogging, logQueries: false, log: function () { return log; } }; } module.exports = DillerConfig;