server: fix config file read/write initial check

This commit is contained in:
jean-emmanuel 2024-02-04 09:57:22 +01:00
parent bf8d9799cc
commit 690add4b38

View file

@ -113,11 +113,20 @@ if (configPathExists) {
} else {
configPath = path.join(baseDir, 'config.json')
}
try {
config = JSON.parse(fs.readFileSync(configPath,'utf-8'))
} catch(e) {
console.error('(ERROR) Could not read config from file:' + configPath)
console.error(e)
if (fs.existsSync(configPath)) {
try {
config = JSON.parse(fs.readFileSync(configPath,'utf-8'))
} catch(e) {
console.error('(ERROR) Could not read config from file:' + configPath)
console.error(e)
}
} else {
try {
fs.writeFileSync(configPath, '{}')
} catch(e) {
console.error('(ERROR) Could not create config file:' + configPath)
console.error(e)
}
}
if (cli) {
for (let k in config) {