mirror of https://github.com/Lissy93/dashy.git
♻️ Moved config validator into services
This commit is contained in:
parent
d60ea923a8
commit
7db441b493
|
@ -11,7 +11,7 @@
|
||||||
"pm2-start": "npx pm2 start server.js",
|
"pm2-start": "npx pm2 start server.js",
|
||||||
"build-watch": "vue-cli-service build --watch --mode production",
|
"build-watch": "vue-cli-service build --watch --mode production",
|
||||||
"build-and-start": "npm-run-all --parallel build-watch start",
|
"build-and-start": "npm-run-all --parallel build-watch start",
|
||||||
"validate-config": "node src/utils/ConfigValidator",
|
"validate-config": "node services/config-validator",
|
||||||
"health-check": "node services/healthcheck"
|
"health-check": "node services/healthcheck"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -4,14 +4,16 @@ const Ajv = require('ajv');
|
||||||
const yaml = require('js-yaml');
|
const yaml = require('js-yaml');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
const schema = require('./ConfigSchema.json');
|
const schema = require('../src/utils/ConfigSchema.json');
|
||||||
|
|
||||||
|
/* Tell AJV to use strict mode, and report all errors */
|
||||||
const validatorOptions = {
|
const validatorOptions = {
|
||||||
strict: true,
|
strict: true,
|
||||||
allowUnionTypes: true,
|
allowUnionTypes: true,
|
||||||
allErrors: true,
|
allErrors: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Initiate AJV validator */
|
||||||
const ajv = new Ajv(validatorOptions);
|
const ajv = new Ajv(validatorOptions);
|
||||||
|
|
||||||
/* Message printed when validation was successful */
|
/* Message printed when validation was successful */
|
||||||
|
@ -58,13 +60,13 @@ const validate = (config) => {
|
||||||
try {
|
try {
|
||||||
const config = yaml.load(fs.readFileSync('./public/conf.yml', 'utf8'));
|
const config = yaml.load(fs.readFileSync('./public/conf.yml', 'utf8'));
|
||||||
validate(config);
|
validate(config);
|
||||||
} catch (e) {
|
} catch (e) { // Something went very wrong...
|
||||||
setIsValidVariable(false);
|
setIsValidVariable(false);
|
||||||
console.log(bigError());
|
console.log(bigError());
|
||||||
console.log('Please ensure that your config file is present, '
|
console.log('Please ensure that your config file is present, '
|
||||||
+ 'has the correct access rights and is parsable. '
|
+ 'has the correct access rights and is parsable. '
|
||||||
+ 'If this warning persists, it may be an issue with the '
|
+ 'If this warning persists, it may be an issue with the '
|
||||||
+ 'validator function. Please raise an issue, and include the following stack trace:\n');
|
+ 'validator function. Please raise an issue, and include the following stack trace:\n');
|
||||||
console.warn('\x1b[33mStack Trace for ConfigValidators.js:\x1b[0m\n', e);
|
console.warn('\x1b[33mStack Trace for config-validator.js:\x1b[0m\n', e);
|
||||||
console.log('\n\n');
|
console.log('\n\n');
|
||||||
}
|
}
|
Loading…
Reference in New Issue