diff --git a/services/mailer/application/config.js b/services/mailer/application/config.js index 23a3ed699..4c54025fb 100644 --- a/services/mailer/application/config.js +++ b/services/mailer/application/config.js @@ -2,26 +2,28 @@ require('require-yaml'); const fs = require('fs-extra'); const packageJson = require('../package.json'); let configPath = `/etc/${packageJson.name}`; -let nginxConfigPath = configPath; -let env = process.env.NODE_ENV ? process.env.NODE_ENV : 'development'; +let config = require('./config/datasources.json'); +let configFiles = [ + `${configPath}/datasources.json`, + `${configPath}/datasources.${env}.json` +]; -if (env === 'development') { - configPath = `${__dirname}/config`; - nginxConfigPath = '../../nginx'; +for (let configFile of configFiles) { + if (fs.accessSync(configFile)) + Object.assign(config, require(configFile)); } -let config = require(`${configPath}/datasources.json`); -let configEnvFile = `${configPath}/datasources.${env}.json`; +let proxyConf = require('../../nginx/config.yml'); +let proxyFiles = [ + `${configPath}/config.yml`, + `${configPath}/config.${env}.yml` +]; -if (fs.existsSync(configEnvFile)) - Object.assign(config, require(configEnvFile)); - -let proxyConf = require(`${nginxConfigPath}/config.yml`); -let proxyEnvFile = `${nginxConfigPath}/config.${env}.yml`; - -if (fs.existsSync(proxyEnvFile)) - Object.assign(proxyConf, require(proxyEnvFile)); +for (let proxyFile of proxyFiles) { + if (fs.accessSync(proxyFile)) + Object.assign(proxyConf, require(proxyFile)); +} config.proxy = proxyConf; config.package = packageJson;