changed config path resolution and displaying debug infos about path locations

This commit is contained in:
Vittorio Palmisano 2021-05-31 12:39:04 +02:00
parent 167f4fdb8b
commit cffc384c8f
2 changed files with 9 additions and 5 deletions

View file

@ -1,4 +1,5 @@
import * as fs from 'fs';
import * as path from 'path';
import convict from 'convict';
import { ipaddress, url } from 'convict-format-with-validator';
import json5 from 'json5';
@ -484,7 +485,7 @@ let configLoaded = false;
// Load config from file
for (const format of [ 'json', 'json5', 'yaml', 'yml', 'toml' ]) // eslint-disable-line no-restricted-syntax
{
const filepath = `./config/config.${format}`;
const filepath = path.normalize(`${__dirname}/../config/config.${format}`);
if (fs.existsSync(filepath))
{
@ -504,7 +505,7 @@ for (const format of [ 'json', 'json5', 'yaml', 'yml', 'toml' ]) // eslint-disab
if (!configLoaded)
{
logger.warn('No config file found, using defaults.');
logger.warn(`No config file found in ${path.normalize(`${__dirname}/../config/`)}, using defaults.`);
configSchema.load({});
}
@ -520,17 +521,19 @@ catch (error: any)
}
// load additional config module (no validation is performed)
if (fs.existsSync(`${__dirname}/../config/config.js`))
const configModuleFilepath = path.normalize(`${__dirname}/../config/config.js`);
if (fs.existsSync(configModuleFilepath))
{
try
{
logger.info(`Loading config module from ${configModuleFilepath}`);
const configModule = require('../config/config.js'); // eslint-disable-line @typescript-eslint/no-var-requires
Object.assign(config, configModule);
}
catch (err)
{
logger.error(`Error loading ${config.configFile} module: ${err.message}`);
logger.error(`Error loading ${configModuleFilepath} module: ${err.message}`);
}
}

View file

@ -15,6 +15,7 @@
"**/*.js"
],
"exclude": [
"./public"
"./public",
"./dist"
]
}