mirror of
https://github.com/PretendoNetwork/account.git
synced 2024-05-20 21:58:04 -04:00
Improved config value set checks
This commit is contained in:
parent
566cd987cf
commit
1b2141ff76
16
package-lock.json
generated
16
package-lock.json
generated
|
@ -27,7 +27,7 @@
|
|||
"image-pixels": "^1.1.1",
|
||||
"joi": "^17.6.1",
|
||||
"kaitai-struct": "^0.9.0",
|
||||
"lodash.has": "^4.5.2",
|
||||
"lodash.get": "^4.4.2",
|
||||
"lodash.set": "^4.3.2",
|
||||
"mii-js": "github:PretendoNetwork/mii-js",
|
||||
"moment": "^2.24.0",
|
||||
|
@ -2055,12 +2055,7 @@
|
|||
"node_modules/lodash.get": {
|
||||
"version": "4.4.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
|
||||
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
|
||||
},
|
||||
"node_modules/lodash.has": {
|
||||
"version": "4.5.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.has/-/lodash.has-4.5.2.tgz",
|
||||
"integrity": "sha512-rnYUdIo6xRCJnQmbVFEwcxF144erlD+M3YcJUVesflU9paQaE8p+fJDcIQrlMYbxoANFL+AB9hZrzSBBk5PL+g=="
|
||||
"integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ=="
|
||||
},
|
||||
"node_modules/lodash.set": {
|
||||
"version": "4.3.2",
|
||||
|
@ -5360,12 +5355,7 @@
|
|||
"lodash.get": {
|
||||
"version": "4.4.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
|
||||
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
|
||||
},
|
||||
"lodash.has": {
|
||||
"version": "4.5.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.has/-/lodash.has-4.5.2.tgz",
|
||||
"integrity": "sha512-rnYUdIo6xRCJnQmbVFEwcxF144erlD+M3YcJUVesflU9paQaE8p+fJDcIQrlMYbxoANFL+AB9hZrzSBBk5PL+g=="
|
||||
"integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ=="
|
||||
},
|
||||
"lodash.set": {
|
||||
"version": "4.3.2",
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
"image-pixels": "^1.1.1",
|
||||
"joi": "^17.6.1",
|
||||
"kaitai-struct": "^0.9.0",
|
||||
"lodash.has": "^4.5.2",
|
||||
"lodash.get": "^4.4.2",
|
||||
"lodash.set": "^4.3.2",
|
||||
"mii-js": "github:PretendoNetwork/mii-js",
|
||||
"moment": "^2.24.0",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const fs = require('fs-extra');
|
||||
const has = require('lodash.has');
|
||||
const get = require('lodash.get');
|
||||
const set = require('lodash.set');
|
||||
const logger = require('../logger');
|
||||
|
||||
|
@ -131,15 +131,18 @@ function configure() {
|
|||
for (const requiredField of requiredFields) {
|
||||
const [keyPath, env, convertType] = requiredField;
|
||||
|
||||
if (!has(config, keyPath)) {
|
||||
if (!process.env[env] || process.env[env].trim() === '') {
|
||||
const configValue = get(config, keyPath);
|
||||
const envValue = get(process.env, keyPath);
|
||||
|
||||
if (!configValue || configValue.trim() === '') {
|
||||
if (!envValue || envValue.trim() === '') {
|
||||
logger.error(`Failed to locate required field ${keyPath}. Set ${keyPath} in config.json or the ${env} environment variable`);
|
||||
|
||||
process.exit(0);
|
||||
} else {
|
||||
logger.info(`${keyPath} not found in config, using environment variable ${env}`);
|
||||
|
||||
const newValue = process.env[env];
|
||||
const newValue = envValue;
|
||||
|
||||
set(config, keyPath, convertType ? convertType(newValue) : newValue);
|
||||
}
|
||||
|
@ -147,8 +150,12 @@ function configure() {
|
|||
}
|
||||
|
||||
// * Check for optional settings
|
||||
if (!has(config, 'redis.client.url')) {
|
||||
if (!process.env.PN_ACT_CONFIG_REDIS_URL || process.env.PN_ACT_CONFIG_REDIS_URL.trim() === '') {
|
||||
|
||||
const redisConfigValue = get(config, 'redis.client.url');
|
||||
const redisEnvValue = get(process.env, 'redis.client.url');
|
||||
|
||||
if (!redisConfigValue || redisConfigValue.trim() === '') {
|
||||
if (!redisEnvValue || redisEnvValue.trim() === '') {
|
||||
logger.warning('Failed to find Redis config. Disabling feature and using in-memory cache');
|
||||
|
||||
disabledFeatures.redis = true;
|
||||
|
|
Loading…
Reference in a new issue