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 = {
|
2022-01-26 09:51:42 +01:00
|
|
|
status: 'SETUP',
|
2021-11-08 11:03:41 +01:00
|
|
|
baseurl: '',
|
|
|
|
hostname: '',
|
2021-09-27 10:42:17 +02:00
|
|
|
server: {
|
2022-05-05 11:11:06 +02:00
|
|
|
host: process.env.GANCIO_HOST || '0.0.0.0',
|
|
|
|
port: process.env.GANCIO_PORT || 13120
|
2021-09-27 10:42:17 +02:00
|
|
|
},
|
|
|
|
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: {},
|
2023-02-17 21:56:31 +01:00
|
|
|
user_locale: path.resolve(process.env.cwd || '', 'user_locale'),
|
2021-10-18 15:46:38 +02:00
|
|
|
upload_path: path.resolve(process.env.cwd || '', 'uploads'),
|
2023-03-16 17:29:48 +01:00
|
|
|
proxy: {
|
|
|
|
protocol: process.env.GANCIO_PROXY_PROTOCOL || '',
|
|
|
|
hostname: process.env.GANCIO_PROXY_HOSTNAME || '',
|
|
|
|
host: process.env.GANCIO_PROXY_HOST || '',
|
|
|
|
port: process.env.GANCIO_PROXY_PORT || '',
|
|
|
|
auth: {
|
|
|
|
username: process.env.GANCIO_PROXY_USERNAME || '',
|
|
|
|
password: process.env.GANCIO_PROXY_PASSWORD || ''
|
|
|
|
},
|
|
|
|
headers: process.env.GANCIO_PROXY_HEADERS && JSON.parse(process.env.GANCIO_PROXY_HEADERS) || {}
|
|
|
|
},
|
2021-09-27 10:42:17 +02:00
|
|
|
write (config_path= process.env.config_path || './config.json') {
|
2022-01-26 09:51:42 +01:00
|
|
|
delete config.status
|
2021-09-27 10:42:17 +02:00
|
|
|
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))
|
2022-08-02 15:14:34 +02:00
|
|
|
config.status = 'CONFIGURED'
|
2024-07-07 19:28:51 +02:00
|
|
|
if (!config.hostname && config.baseurl) {
|
2021-11-08 11:03:41 +01:00
|
|
|
config.hostname = new URL.URL(config.baseurl).hostname
|
|
|
|
}
|
2021-09-27 10:42:17 +02:00
|
|
|
} else {
|
2022-01-26 09:51:42 +01:00
|
|
|
config.status = 'SETUP'
|
2023-07-08 22:43:12 +02:00
|
|
|
console.info('> Configuration file does not exists...')
|
2021-09-27 10:42:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-18 01:15:52 +02:00
|
|
|
config.load()
|
2024-07-07 19:28:51 +02:00
|
|
|
module.exports = config
|