后台:独立数据库,路径转发
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user