Skip to content

Commit

Permalink
fix(configuration): Only validate the initial configuration against t…
Browse files Browse the repository at this point in the history
…he schema (#2622)
  • Loading branch information
daffl authored May 4, 2022
1 parent 2bbb103 commit 386c5e2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/configuration/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,24 @@ export = function init (schema?: Schema<any>) {
return config;
}


const configuration: { [key: string]: unknown } = { ...config };

debug(`Initializing configuration for ${config.util.getEnv('NODE_ENV')} environment`);

Object.keys(config).forEach(name => {
const value = (config as any)[name];
Object.keys(configuration).forEach(name => {
const value = configuration[name];
debug(`Setting ${name} configuration value to`, value);
app.set(name, value);
});

if (schema) {
app.hooks({
setup: [async (context: ApplicationHookContext, next: NextFunction) => {
await schema.validate(context.app.settings);
setup: [async (_context: ApplicationHookContext, next: NextFunction) => {
await schema.validate(configuration);
await next();
}]
})
});
}

return config;
Expand Down

0 comments on commit 386c5e2

Please # to comment.