Comparing version 2.0.13 to 2.0.14
@@ -5,2 +5,6 @@ # Changelog | ||
## [2.0.14][] - 2021-03-13 | ||
- Use metaschema for config validation | ||
## [2.0.13][] - 2021-03-05 | ||
@@ -112,3 +116,4 @@ | ||
[unreleased]: https://github.com/metarhia/impress/compare/v2.0.13...HEAD | ||
[unreleased]: https://github.com/metarhia/impress/compare/v2.0.14...HEAD | ||
[2.0.14]: https://github.com/metarhia/impress/compare/v2.0.13...v2.0.14 | ||
[2.0.13]: https://github.com/metarhia/impress/compare/v2.0.12...v2.0.13 | ||
@@ -115,0 +120,0 @@ [2.0.12]: https://github.com/metarhia/impress/compare/v2.0.11...v2.0.12 |
@@ -10,3 +10,5 @@ 'use strict'; | ||
const metavm = require('metavm'); | ||
const { loadSchema } = require('metaschema'); | ||
const CONFIG_SECTIONS = ['log', 'scale', 'server', 'sessions']; | ||
const PATH = process.cwd(); | ||
@@ -19,9 +21,27 @@ const CFG_PATH = path.join(PATH, 'application/config'); | ||
console.error(err); | ||
process.exit(0); | ||
process.exit(1); | ||
}; | ||
const validateConfig = async (config) => { | ||
const schemaPath = path.join(__dirname, 'schemas/config'); | ||
let valid = true; | ||
for (const section of CONFIG_SECTIONS) { | ||
const schema = await loadSchema(path.join(schemaPath, section + '.js')); | ||
const checkResult = schema.check(config[section]); | ||
if (!checkResult.valid) { | ||
for (const err of checkResult.errors) console.log(err); | ||
valid = false; | ||
} | ||
} | ||
if (!valid) { | ||
console.error('Can not start server'); | ||
process.exit(1); | ||
} | ||
}; | ||
(async () => { | ||
const context = metavm.createContext({ process }); | ||
const options = { mode: process.env.MODE, context, names: ['server'] }; | ||
const options = { mode: process.env.MODE, context }; | ||
const config = await new Config(CFG_PATH, options).catch(configError); | ||
await validateConfig(config); | ||
if (!config.server) configError(new Error('Section "server" is not found')); | ||
@@ -28,0 +48,0 @@ const { balancer, ports = [], workers = {} } = config.server; |
@@ -10,4 +10,24 @@ 'use strict'; | ||
const { Server } = metarhia.metacom; | ||
const { loadSchema } = metarhia.metaschema; | ||
const { Auth } = require('./auth.js'); | ||
const CONFIG_SECTIONS = ['log', 'scale', 'server', 'sessions']; | ||
const validateConfig = async (config) => { | ||
const schemaPath = path.join(__dirname, '../schemas/config'); | ||
let valid = true; | ||
for (const section of CONFIG_SECTIONS) { | ||
const schema = await loadSchema(path.join(schemaPath, section + '.js')); | ||
const checkResult = schema.check(config[section]); | ||
if (!checkResult.valid) { | ||
for (const err of checkResult.errors) console.log(err); | ||
valid = false; | ||
} | ||
} | ||
if (!valid) { | ||
console.error('Can not start server'); | ||
process.exit(1); | ||
} | ||
}; | ||
(async () => { | ||
@@ -18,2 +38,3 @@ const configPath = path.join(application.path, 'config'); | ||
const config = await new Config(configPath, options); | ||
await validateConfig(config); | ||
const logPath = path.join(application.root, 'log'); | ||
@@ -20,0 +41,0 @@ const home = application.root; |
{ | ||
"name": "impress", | ||
"version": "2.0.13", | ||
"version": "2.0.14", | ||
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>", | ||
@@ -72,3 +72,3 @@ "description": "Enterprise application server for Node.js", | ||
"metalog": "^3.1.0", | ||
"metaschema": "^1.0.0", | ||
"metaschema": "^1.0.2", | ||
"metautil": "^3.5.1", | ||
@@ -78,4 +78,4 @@ "metavm": "^1.0.0" | ||
"devDependencies": { | ||
"@types/node": "^14.14.31", | ||
"eslint": "^7.21.0", | ||
"@types/node": "^14.14.34", | ||
"eslint": "^7.22.0", | ||
"eslint-config-metarhia": "^7.0.1", | ||
@@ -82,0 +82,0 @@ "eslint-config-prettier": "^8.1.0", |
@@ -5,10 +5,4 @@ ({ | ||
writeBuffer: { type: 'number', default: 64 * 1024 }, | ||
toFile: { | ||
type: { array: 'string' }, | ||
default: ['error', 'warn', 'info', 'debug', 'log'], | ||
}, | ||
toStdout: { | ||
type: { array: 'string' }, | ||
default: ['error', 'warn', 'info', 'debug', 'log'], | ||
}, | ||
toFile: { array: 'string' }, | ||
toStdout: { array: 'string' }, | ||
}); |
({ | ||
cloud: 'string', | ||
server: 'string', | ||
instance: { type: 'flag', enum: ['standalone', 'controller', 'server'] }, | ||
instance: { enum: ['standalone', 'controller', 'server'] }, | ||
token: { type: 'string', length: 32 }, | ||
gc: { type: 'number', default: 60 * 60 * 1000 }, | ||
}); |
({ | ||
host: 'string', | ||
balancer: 'number', | ||
protocol: { type: 'flag', enum: ['string'] }, | ||
ports: { type: { arrey: 'number', default: [8001] } }, | ||
protocol: { enum: ['http', 'https'] }, | ||
ports: { array: 'number' }, | ||
timeout: { type: 'number', default: 5000 }, | ||
@@ -7,0 +7,0 @@ queue: { |
@@ -11,3 +11,3 @@ ({ | ||
expire: { type: 'number', default: 24 * 60 * 60 * 1000 }, | ||
persistent: { type: 'boolean', default: true }, | ||
persistent: 'boolean', | ||
limits: { | ||
@@ -14,0 +14,0 @@ ip: { type: 'number', default: 20 }, |
({ | ||
parameters: 'object', | ||
validate: 'function', | ||
method: 'function', | ||
returns: 'object', | ||
assert: 'function', | ||
caption: { type: 'string', required: false }, | ||
description: { type: 'string', required: false }, | ||
access: { type: 'Access', required: false }, | ||
parameters: { type: 'Schema', required: false }, | ||
validate: { type: 'function', required: false }, | ||
timeout: { type: 'number', required: false }, | ||
queue: { type: 'QueueParameters', required: false }, | ||
sirializer: { type: 'Serializer', required: false }, | ||
protocols: { array: 'Protocols', required: false }, | ||
deprecated: { type: 'boolean', required: false }, | ||
method: 'AsyncFuction', | ||
returns: { type: 'Schema', required: false }, | ||
assert: { type: 'function', required: false }, | ||
script: { type: 'function', required: false }, | ||
examples: { array: 'Example', required: false }, | ||
application: { type: 'Application', required: false }, | ||
}); |
@@ -27,5 +27,5 @@ type GroupAccess = { group: string }; | ||
assert?: Function; | ||
script: Function; | ||
script?: Function; | ||
examples?: Array<Example>; | ||
application: Application; | ||
application?: Application; | ||
} |
@@ -6,7 +6,6 @@ { | ||
"strict": true, | ||
"noEmit": true, | ||
"baseUrl": ".", | ||
"preserveWatchOutput": true | ||
}, | ||
"include": ["*.d.ts"] | ||
"include": ["*.d.ts", "*.ts"] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41103
852
Updatedmetaschema@^1.0.2