zipline/server/validateConfig.js

45 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-06-23 13:20:20 -05:00
const Logger = require('../src/lib/logger');
function dot(str, obj) {
return str.split('.').reduce((a,b) => a[b], obj);
}
const path = (path, type) => ({ path, type });
module.exports = async config => {
const paths = [
path('core.secure', 'boolean'),
path('core.secret', 'string'),
path('core.host', 'string'),
path('core.port', 'number'),
2021-08-28 13:32:09 -05:00
path('core.database_url', 'string'),
2021-06-23 13:20:20 -05:00
path('uploader.route', 'string'),
path('uploader.length', 'number'),
path('uploader.directory', 'string'),
path('uploader.admin_limit', 'number'),
path('uploader.user_limit', 'number'),
path('uploader.disabled_extentions', 'object'),
2021-06-23 13:20:20 -05:00
];
let errors = 0;
for (let i = 0, L = paths.length; i !== L; ++i) {
const path = paths[i];
const value = dot(path.path, config);
if (value === undefined) {
Logger.get('config').error(`there was no ${path.path} in config which was required`);
2021-06-23 13:20:20 -05:00
++errors;
}
const type = typeof value;
2021-06-23 13:20:20 -05:00
if (value !== undefined && type !== path.type) {
Logger.get('config').error(`expected ${path.type} on ${path.path}, but got ${type}`);
++errors;
}
}
if (errors !== 0) {
Logger.get('config').error(`exiting due to ${errors} errors`);
process.exit(1);
}
};