后台:独立数据库,路径转发

This commit is contained in:
luying
2021-11-22 19:56:16 +08:00
parent 9d9ed77423
commit 7940e6d09d
16 changed files with 256 additions and 303 deletions
+11
View File
@@ -1,6 +1,7 @@
import 'reflect-metadata'
import * as mongoose from 'mongoose';
import { Application, IBoot } from 'egg';
import { loadGmDb } from '@db/index';
export default class FooBoot implements IBoot {
private readonly app: Application;
@@ -14,6 +15,7 @@ export default class FooBoot implements IBoot {
// Config, plugin files are referred,`
// this is the last chance to modify the config.
await this.connectDB(this.app)
await this.connectGMDB(this.app);
}
configDidLoad() {
@@ -52,6 +54,15 @@ export default class FooBoot implements IBoot {
}
}
public async connectGMDB(app: Application) {
const { url, options } = app.config.gmmongoose
if (url) {
const connection = await mongoose.createConnection(url, options)
app.context.connectionGM = connection;
loadGmDb(connection);
}
}
//#endregion
}