app.js 652 B

1234567891011121314151617181920212223242526272829
  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. name: 'admin',
  12. phone: 'admin',
  13. password: { secret: '123456' },
  14. };
  15. await this.app.model.Admin.create(data);
  16. }
  17. }
  18. async serverDidReady() {
  19. // 应用已经启动完毕
  20. const ctx = await this.app.createAnonymousContext();
  21. // 检查种子
  22. // await ctx.service.install.index();
  23. await ctx.service.util.rabbitMq.mission();
  24. }
  25. }
  26. module.exports = AppBootHook;