Fixed meshctrl.js config.json path search.
Ylian Saint-Hilaire committed
Jun 23, 2020 at 12:35 UTC
329b37c3a3746df62b7531929277b2353fbf6344
1 file changed
+3
-2
meshctrl.js
+3
-2
@@ -451,10 +451,11 @@ function performConfigOperations(args) {
451
if (fs.existsSync(configFile) == false) { configFile = path.join(__dirname, 'config.json'); }
452
if (fs.existsSync(configFile) == false) { configFile = path.join(__dirname, 'meshcentral-data', 'config.json'); }
453
if (fs.existsSync(configFile) == false) { configFile = path.join(__dirname, '..', 'meshcentral-data', 'config.json'); }
454
+ if (fs.existsSync(configFile) == false) { configFile = path.join(__dirname, '..', '..', 'meshcentral-data', 'config.json'); }
455
if (fs.existsSync(configFile) == false) { console.log("Unable to find config.json."); return; }
456
var config = null;
456
- try { config = fs.readFileSync(configFile); } catch (ex) { console.log("Error: Unable to read config.json"); return; }
457
- try { config = JSON.parse(config); } catch (ex) { console.log("Error: Unable to parse config.json"); return; }
457
+ try { config = fs.readFileSync(configFile).toString('utf8'); } catch (ex) { console.log("Error: Unable to read config.json"); return; }
458
+ try { config = require(configFile); } catch (e) { console.log('ERROR: Unable to parse ' + configFilePath + '.'); return null; }
459
if (args.adddomain != null) {
460
didSomething++;
461
if (config.domains == null) { config.domains = {}; }