diff --git a/src/config/configuration.js b/src/config/configuration.js index cafaa07..ba0d0a8 100644 --- a/src/config/configuration.js +++ b/src/config/configuration.js @@ -1,3 +1,4 @@ +import fs from "fs"; import path from "path"; import { fileURLToPath } from "url"; @@ -10,8 +11,7 @@ const __dirname = path.dirname(__filename); class Config { constructor() { this.location = Config.determineLocation(); - // eslint-disable-next-line import/no-dynamic-require, global-require - this.fields = require(`${this.location}`); + this.fields = Config.readFileContents(this.location); } static getInstance() { @@ -25,6 +25,17 @@ class Config { return path.join(__dirname, "..", "..", process.env.SEASONED_CONFIG); } + static readFileContents(location) { + let content = {}; + try { + content = JSON.parse(fs.readFileSync(location, { encoding: "utf-8" })); + } catch (err) { + console.error(`Error loading configuration file at path: ${location}`); + } + + return content; + } + get(section, option) { if ( this.fields[section] === undefined ||