Read also global config in server backend.

The configuration file etc/config.yaml is exposed to the
server backend under require('configuration').global.

Note that at some point it will probably make sense to
merge the two config files.
This commit is contained in:
D. Berge
2020-08-25 08:48:10 +02:00
parent 9fa76df446
commit 650ed998c6
3 changed files with 16 additions and 1 deletions

View File

@@ -1,9 +1,11 @@
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
const YAML = require('yaml');
const cfgPrefix = process.env.DOUGAL_ROOT || ((process.env.HOME || ".") + "/software");
const cfgPath = process.env.DOUGAL_API_CONFIG || (cfgPrefix+"/etc/www/config.json");
const globalCfgPath = cfgPrefix+"/etc/config.yaml";
let config = {}
@@ -51,6 +53,13 @@ try {
}
}
if (fs.existsSync(globalCfgPath)) {
const text = fs.readFileSync(globalCfgPath, 'utf8');
if (text) {
config.global = YAML.parse(text);
}
}
} catch (err) {
console.error(err);
}

View File

@@ -613,6 +613,11 @@
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ=="
},
"yaml": {
"version": "2.0.0-0",
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.0.0-0.tgz",
"integrity": "sha512-+n+AwzE2hK2j21p36UB2foND6RYQU4PQkdPCK4YF2OKz8BbiNI+NvKS79CpyDChw3k/0L9jnChkjEzKoiu2C7w=="
}
}
}

View File

@@ -13,6 +13,7 @@
"express": "^4.17.1",
"express-jwt": "^6.0.0",
"jsonwebtoken": "^8.5.1",
"pg": "^8.3.0"
"pg": "^8.3.0",
"yaml": "^2.0.0-0"
}
}