From 7db441b493e0ad3a9734b1def1ce3d2855b7d7f9 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 25 Jul 2021 17:42:01 +0100 Subject: [PATCH] :recycle: Moved config validator into services --- package.json | 2 +- .../ConfigValidator.js => services/config-validator.js | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) rename src/utils/ConfigValidator.js => services/config-validator.js (89%) diff --git a/package.json b/package.json index 2dc77a18..97567266 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "pm2-start": "npx pm2 start server.js", "build-watch": "vue-cli-service build --watch --mode production", "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" }, "dependencies": { diff --git a/src/utils/ConfigValidator.js b/services/config-validator.js similarity index 89% rename from src/utils/ConfigValidator.js rename to services/config-validator.js index 5f9bfdb6..bc6545e3 100644 --- a/src/utils/ConfigValidator.js +++ b/services/config-validator.js @@ -4,14 +4,16 @@ const Ajv = require('ajv'); const yaml = require('js-yaml'); 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 = { strict: true, allowUnionTypes: true, allErrors: true, }; +/* Initiate AJV validator */ const ajv = new Ajv(validatorOptions); /* Message printed when validation was successful */ @@ -58,13 +60,13 @@ const validate = (config) => { try { const config = yaml.load(fs.readFileSync('./public/conf.yml', 'utf8')); validate(config); -} catch (e) { +} catch (e) { // Something went very wrong... setIsValidVariable(false); console.log(bigError()); console.log('Please ensure that your config file is present, ' + 'has the correct access rights and is parsable. ' + 'If this warning persists, it may be an issue with the ' + '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'); }