Skip to content

Commit

Permalink
fix: controller 中的 hooks,比 autoload 中的 hook 靠前,导致 req.$appConfig 未定义
Browse files Browse the repository at this point in the history
  • Loading branch information
meixg committed Dec 6, 2021
1 parent aa7baa3 commit b06bdcf
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/app-autoload/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ async function load(appConfig: AppConfig, childInstance: FastifyInstance) {
childInstance.decorate('$appConfig', configProxy);
childInstance.decorate('molecule', molecule);

childInstance.addHook('preValidation', preValidation);
childInstance.addHook('onRequest', onRequestFactory(configProxy, childInstance));
childInstance.addHook('preHandler', loggerMiddleware);
childInstance.addHook('preHandler', preHandlerFactory(appConfig.name));
childInstance.addHook('onSend', onSend);

// load module plugins
if (appConfig.pluginConfig) {
for (const [name, config] of Object.entries(appConfig.pluginConfig)) {
Expand Down Expand Up @@ -133,12 +139,6 @@ async function load(appConfig: AppConfig, childInstance: FastifyInstance) {
});
}

childInstance.addHook('preValidation', preValidation);
childInstance.addHook('onRequest', onRequestFactory(configProxy, childInstance));
childInstance.addHook('preHandler', loggerMiddleware);
childInstance.addHook('preHandler', preHandlerFactory(appConfig.name));
childInstance.addHook('onSend', onSend);

return childInstance;
}

Expand Down

0 comments on commit b06bdcf

Please sign in to comment.