-
Notifications
You must be signed in to change notification settings - Fork 1
/
base-config.js
42 lines (37 loc) · 1.22 KB
/
base-config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
var fs = require('fs');
var os = require('os');
var path = require('path');
var xtend = require('xtend');
var internalIp = require('internal-ip');
var pkg = require(path.dirname(require.main.filename) + '/package.json');
var pkgConfig = pkg.config || {};
var config = {
name: pkg.name,
version: pkg.version,
port: pkgConfig.port,
services: pkgConfig.services,
loose_services: pkgConfig.loose_services,
environment: 'development',
consul: false,
ip_address: internalIp.v4(),
container_id: os.hostname() || 'unknown',
log_level: 'info'
};
if (process.env.CONFIG_FILE) {
var localConfig;
try {
localConfig = fs.readFileSync(process.env.CONFIG_FILE, 'utf8');
localConfig = JSON.parse(localConfig);
} catch (e) {
throw e;
}
console.log('[magistrate] Using local configuration file');
config = xtend(config, localConfig);
}
if (process.env.SERVICE_NAME) config.name = process.env.SERVICE_NAME;
if (process.env.NODE_ENV) config.environment = process.env.NODE_ENV;
if (process.env.CONSUL || process.env.LOCAL_CONSUL) config.consul = true;
if (process.env.LOG_LEVEL) config.log_level = process.env.LOG_LEVEL;
console.log('[magistrate] Base configuration is:', config);
module.exports = config;