app.js 662 B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. class AppBootHook {
  3. constructor(app) {
  4. this.app = app;
  5. }
  6. async willReady() {
  7. const data = await this.app.model.Admin.findOne();
  8. if (!data) {
  9. // 没有管理员,初始化一个
  10. const data = {
  11. account: 'admin',
  12. password: { secret: 'freeAdmin' },
  13. };
  14. await this.app.model.Admin.create(data);
  15. }
  16. }
  17. async serverDidReady() {
  18. // 应用已经启动完毕
  19. const ctx = await this.app.createAnonymousContext();
  20. // 检查种子
  21. // await ctx.service.install.index();
  22. await ctx.service.util.rabbitMq.mission();
  23. }
  24. }
  25. module.exports = AppBootHook;