* Populate a LoadConfig entirely from environment variables. * * This is the way a base config is normally accomplished, but not for independent loads. * * This function exists in part to reduce the circular dependency of variable initializations * in the config.js file * @param {s
(environments)
| 1364 | * @returns {Load} |
| 1365 | */ |
| 1366 | static fromEnvironment(environments) { |
| 1367 | let env = new Env(); |
| 1368 | |
| 1369 | if (environments !== undefined) { |
| 1370 | environments = environments.split(','); |
| 1371 | env.setEnv('nodeEnv', environments.join(',')); |
| 1372 | } else { |
| 1373 | let nodeConfigEnv = env.initParam('NODE_CONFIG_ENV'); |
| 1374 | let nodeEnv = env.initParam('NODE_ENV'); |
| 1375 | |
| 1376 | if (nodeConfigEnv) { |
| 1377 | env.setEnv('nodeEnv', 'NODE_CONFIG_ENV'); |
| 1378 | nodeEnv = nodeConfigEnv; |
| 1379 | } else if (nodeEnv) { |
| 1380 | env.setEnv('nodeEnv', 'NODE_ENV'); |
| 1381 | env.setEnv('NODE_CONFIG_ENV', nodeEnv); //TODO: This is a bug asserted in the tests |
| 1382 | } else { |
| 1383 | nodeEnv = 'development'; |
| 1384 | env.setEnv('nodeEnv', 'default'); |
| 1385 | env.setEnv('NODE_ENV', nodeEnv); |
| 1386 | env.setEnv('NODE_CONFIG_ENV', nodeEnv); //TODO: This is a bug asserted in the tests |
| 1387 | } |
| 1388 | |
| 1389 | environments = nodeEnv.split(','); |
| 1390 | } |
| 1391 | |
| 1392 | let configDir = env.initParam('NODE_CONFIG_DIR'); |
| 1393 | let appInstance = env.initParam('NODE_APP_INSTANCE'); |
| 1394 | let gitCrypt = !env.initParam('CONFIG_SKIP_GITCRYPT'); |
| 1395 | let parser = _loadParser(env.initParam('NODE_CONFIG_PARSER'), configDir); |
| 1396 | let hostName = env.initParam('HOST') || env.initParam('HOSTNAME'); |
| 1397 | |
| 1398 | // Determine the host name from the OS module, $HOST, or $HOSTNAME |
| 1399 | // Remove any . appendages, and default to null if not set |
| 1400 | try { |
| 1401 | if (!hostName) { |
| 1402 | hostName = OS.hostname(); |
| 1403 | } |
| 1404 | } catch (e) { |
| 1405 | hostName = ''; |
| 1406 | } |
| 1407 | |
| 1408 | env.setEnv('HOSTNAME', hostName); |
| 1409 | |
| 1410 | /** @type {LoadOptions} */ |
| 1411 | let options = { |
| 1412 | configDir: configDir ?? DEFAULT_CONFIG_DIR, |
| 1413 | nodeEnv: environments, |
| 1414 | hostName, |
| 1415 | parser, |
| 1416 | appInstance, |
| 1417 | gitCrypt |
| 1418 | }; |
| 1419 | |
| 1420 | return new Load(options, env); |
| 1421 | } |
| 1422 | } |
| 1423 |
no test coverage detected