2021-09-27 10:42:17 +02:00
|
|
|
const fs = require('fs')
|
|
|
|
const path = require('path')
|
2021-11-08 11:03:41 +01:00
|
|
|
const URL = require('url')
|
2021-09-27 10:42:17 +02:00
|
|
|
|
|
|
|
let config = {
|
|
|
|
firstrun: true,
|
2021-11-08 11:03:41 +01:00
|
|
|
baseurl: '',
|
|
|
|
hostname: '',
|
2021-09-27 10:42:17 +02:00
|
|
|
server: {
|
2021-10-25 11:05:45 +02:00
|
|
|
host: '0.0.0.0',
|
2021-09-27 10:42:17 +02:00
|
|
|
port: 13120
|
|
|
|
},
|
|
|
|
log_level: 'debug',
|
2021-10-18 15:46:38 +02:00
|
|
|
log_path: path.resolve(process.env.cwd || '', 'logs'),
|
2021-09-27 10:42:17 +02:00
|
|
|
db: {},
|
2021-10-18 15:46:38 +02:00
|
|
|
upload_path: path.resolve(process.env.cwd || '', 'uploads'),
|
2021-09-27 10:42:17 +02:00
|
|
|
write (config_path= process.env.config_path || './config.json') {
|
|
|
|
return fs.writeFileSync(config_path, JSON.stringify(config, null, 2))
|
|
|
|
},
|
|
|
|
|
|
|
|
load () {
|
|
|
|
// load configuration from file
|
|
|
|
const config_path = process.env.config_path || './config.json'
|
2021-09-30 11:15:21 +02:00
|
|
|
console.info(`> Reading configuration from: ${config_path}`)
|
2021-09-27 10:42:17 +02:00
|
|
|
if (fs.existsSync(config_path)) {
|
|
|
|
const configContent = fs.readFileSync(config_path)
|
|
|
|
config = Object.assign(config, JSON.parse(configContent))
|
|
|
|
config.firstrun = false
|
2021-11-08 11:03:41 +01:00
|
|
|
if (!config.hostname) {
|
|
|
|
config.hostname = new URL.URL(config.baseurl).hostname
|
|
|
|
}
|
2021-09-27 10:42:17 +02:00
|
|
|
} else {
|
|
|
|
config.firstrun = true
|
2021-09-30 11:15:21 +02:00
|
|
|
console.info('> Configuration file does not exists, running setup..')
|
2021-09-27 10:42:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
config.load()
|
|
|
|
|
|
|
|
module.exports = config
|