app.js 1.2 KB
const path = require('path');
// module.exports = app => {
// app.beforeStart(async function() {
//   // 应用会等待这个函数执行完成才启动
//   // await app.model.sync({ force: true }); // 开发环境使用
//   await app.model.sync({});
// });
class AppBootHook {
  constructor(app) {
    this.app = app;
    this.helper = app.helper;
  }
  async configWillLoad() {
    console.log(`
          ◆ 项目:广联赛讯历史保单数据服务
          ◆ 语言:Javascript
          ◆ 框架:Node.js + Egg.js + MySql
          ◆ 版本控制: git-github
          ◆ 代码风格:eslint-standard
          ◆ 编辑器: VSCode
          ◆ 数据库:  mysql
          ◆ 服务器端脚本: Node.js
          ◆ author: limin
      `)
  }
  async didReady() {
    const ctx = await this.app.createAnonymousContext();
    console.log('          ◆ 加载校验规则\r\n')
    console.log('\r\n          ◆ 应用启动成功!\r\n')
    await this._init_user_validations_(ctx);
  }

  async _init_user_validations_() {
    const directory = path.join(this.app.config.baseDir, './app/validate');
    this.app.loader.loadToApp(directory, 'validate');
  }
}

module.exports = AppBootHook;