app.js 780 B

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. class AppBootHook {
  3. constructor(app) {
  4. this.app = app;
  5. }
  6. configWillLoad() {
  7. const mongoConfig = this.app.config.mongoose;
  8. const mongoClient = require('mongodb').MongoClient;
  9. const connectUrl = `mongodb://${mongoConfig.options.user}:${mongoConfig.options.pass}@localhost:27017/wxCache?authSource=admin`;
  10. mongoClient.connect(connectUrl, (err, db) => {
  11. if (db) this.app.config.canUseMongoDb = true;
  12. else this.app.config.canUseMongoDb = false;
  13. });
  14. }
  15. async didLoad() {
  16. // console.log(this.app);
  17. }
  18. async willReady() {
  19. // 所有的插件都已启动完毕,但是应用整体还未 ready
  20. // 可以做一些数据初始化等操作,这些操作成功才会启动应用
  21. }
  22. }
  23. module.exports = AppBootHook;