gancio-upstream/server/config.js

36 lines
1,019 B
JavaScript
Raw Normal View History

2021-09-27 10:42:17 +02:00
const fs = require('fs')
const path = require('path')
let config = {
firstrun: true,
baseurl: "http://localhost:13120",
server: {
host: '127.0.0.1',
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
} 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