mirror of
https://github.com/jc21/nginx-proxy-manager.git
synced 2024-08-30 18:22:48 +00:00
2a07445005
- No longer use config npm package - Prefer config from env vars, though still has support for config file - No longer writes a config file for database config - Writes keys to a new file in /data folder - Removes a lot of cruft and improves config understanding
50 lines
1.0 KiB
JavaScript
50 lines
1.0 KiB
JavaScript
const _ = require('lodash');
|
|
const error = require('../error');
|
|
const definitions = require('../../schema/definitions.json');
|
|
|
|
RegExp.prototype.toJSON = RegExp.prototype.toString;
|
|
|
|
const ajv = require('ajv')({
|
|
verbose: true,
|
|
allErrors: true,
|
|
format: 'full', // strict regexes for format checks
|
|
coerceTypes: true,
|
|
schemas: [
|
|
definitions
|
|
]
|
|
});
|
|
|
|
/**
|
|
*
|
|
* @param {Object} schema
|
|
* @param {Object} payload
|
|
* @returns {Promise}
|
|
*/
|
|
function validator (schema, payload) {
|
|
return new Promise(function (resolve, reject) {
|
|
if (!payload) {
|
|
reject(new error.InternalValidationError('Payload is falsy'));
|
|
} else {
|
|
try {
|
|
let validate = ajv.compile(schema);
|
|
|
|
let valid = validate(payload);
|
|
if (valid && !validate.errors) {
|
|
resolve(_.cloneDeep(payload));
|
|
} else {
|
|
let message = ajv.errorsText(validate.errors);
|
|
reject(new error.InternalValidationError(message));
|
|
}
|
|
|
|
} catch (err) {
|
|
reject(err);
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
module.exports = validator;
|