123456789101112131415161718192021222324252627 |
- 'use strict';
- class AppBootHook {
- constructor(app) {
- this.app = app;
- }
- configWillLoad() {
- const mongoConfig = this.app.config.mongoose;
- const mongoClient = require('mongodb').MongoClient;
- const connectUrl = `mongodb://${mongoConfig.options.user}:${mongoConfig.options.pass}@localhost:27017/wxCache?authSource=admin`;
- mongoClient.connect(connectUrl, (err, db) => {
- if (db) this.app.config.canUseMongoDb = true;
- else this.app.config.canUseMongoDb = false;
- });
- }
- async didLoad() {
- // console.log(this.app);
- }
- async willReady() {
- // 所有的插件都已启动完毕,但是应用整体还未 ready
- // 可以做一些数据初始化等操作,这些操作成功才会启动应用
- }
- }
- module.exports = AppBootHook;
|