app.js 914 B

1234567891011121314151617181920212223242526272829303132333435
  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: '123456' },
  13. };
  14. await this.app.model.Admin.create(data);
  15. }
  16. // 初始化系统设置
  17. const config = await this.app.model.Config.findOne();
  18. if (!config) {
  19. // 没有系统设置,初始化一个
  20. const data = { config: {} };
  21. await this.app.model.Config.create(data);
  22. }
  23. }
  24. async serverDidReady() {
  25. // 应用已经启动完毕
  26. const ctx = await this.app.createAnonymousContext();
  27. await ctx.service.card.login();
  28. // // 检查种子
  29. // // await ctx.service.install.index();
  30. // await ctx.service.util.rabbitMq.mission();
  31. }
  32. }
  33. module.exports = AppBootHook;