2021-07-03 13:56:53 +00:00
|
|
|
import fs from 'fs'
|
|
|
|
import Nconf from 'nconf-lite'
|
2022-08-13 21:52:45 +00:00
|
|
|
import { Util } from 'service-core'
|
2021-07-03 13:56:53 +00:00
|
|
|
|
|
|
|
const nconf = new Nconf()
|
2017-12-09 21:51:18 +00:00
|
|
|
|
|
|
|
// Helper method for global usage.
|
|
|
|
nconf.inTest = () => nconf.get('NODE_ENV') === 'test'
|
|
|
|
|
|
|
|
// Config follow the following priority check order:
|
2022-08-13 21:52:45 +00:00
|
|
|
// 1. Enviroment variables
|
|
|
|
// 2. package.json
|
2017-12-09 21:51:18 +00:00
|
|
|
// 3. config/config.json
|
|
|
|
// 4. config/config.default.json
|
|
|
|
|
2022-08-13 21:52:45 +00:00
|
|
|
// Load enviroment variables as first priority
|
|
|
|
nconf.env({
|
|
|
|
separator: '__',
|
|
|
|
whitelist: [
|
|
|
|
'NODE_ENV',
|
|
|
|
'server__port',
|
|
|
|
'server__host',
|
|
|
|
'bunyan__name',
|
|
|
|
'frontend__url',
|
|
|
|
'fileSize',
|
|
|
|
'name',
|
|
|
|
'NODE_VERSION',
|
|
|
|
],
|
|
|
|
parseValues: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Load empty overrides that can be overwritten later
|
|
|
|
nconf.overrides({})
|
|
|
|
|
|
|
|
let util = new Util(import.meta.url)
|
|
|
|
let pckg = JSON.parse(fs.readFileSync(util.getPathFromRoot(`../package.json`)))
|
|
|
|
|
|
|
|
nconf.defaults({
|
|
|
|
"name": pckg.name,
|
|
|
|
"version": pckg.version,
|
|
|
|
"NODE_ENV": "development",
|
|
|
|
"server": {
|
|
|
|
"port": 4040,
|
|
|
|
"host": "0.0.0.0"
|
|
|
|
},
|
|
|
|
"bunyan": {
|
|
|
|
"name": "storage-upload",
|
|
|
|
"streams": [{
|
|
|
|
"stream": "process.stdout",
|
|
|
|
"level": "debug"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"sites": {
|
|
|
|
},
|
|
|
|
"uploadFolder": "./public",
|
|
|
|
"fileSize": 524288000
|
|
|
|
})
|
2017-12-09 21:51:18 +00:00
|
|
|
|
2021-07-03 13:56:53 +00:00
|
|
|
export default nconf
|