server: fix config file read/write initial check
This commit is contained in:
parent
bf8d9799cc
commit
690add4b38
1 changed files with 14 additions and 5 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue