Skip to content

Commit

Permalink
prioritize local configs over system-wide (and respect $XDG_CONFIG_HOME)
Browse files Browse the repository at this point in the history
  • Loading branch information
ExperiBass committed Dec 28, 2023
1 parent 2e3797e commit beb14c9
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ const debugErrorLog = debug("btcexp:error");
const debugPerfLog = debug("btcexp:actionPerformace");
const debugAccessLog = debug("btcexp:access");

const xdgHome = process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config");
const configPaths = [
path.join(os.homedir(), ".config", "btc-rpc-explorer.env"),
path.join("/etc", "btc-rpc-explorer", ".env"),
path.join(process.cwd(), ".env"),
path.join(xdgHome, "btc-rpc-explorer.env"),
path.join(xdgHome, "btc-rpc-explorer", ".env"),
path.join("/etc", "btc-rpc-explorer", ".env"),
];

debugLog("Searching for config files...");
let configFileLoaded = false;
configPaths.forEach(path => {
for (const path of configPaths) {
if (fs.existsSync(path)) {
debugLog(`Config file found at ${path}, loading...`);

Expand All @@ -43,11 +45,11 @@ configPaths.forEach(path => {
}

configFileLoaded = true;

break
} else {
debugLog(`Config file not found at ${path}, continuing...`);
}
});
};

if (!configFileLoaded) {
debugLog("No config files found. Using all defaults.");
Expand Down

0 comments on commit beb14c9

Please sign in to comment.