🐞 fix(数据库): web和gm添加userlog副数据库
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import 'reflect-metadata'
|
||||
import * as mongoose from 'mongoose';
|
||||
import { Application, IBoot } from 'egg';
|
||||
import { loadGmDb } from '@db/index';
|
||||
import { loadGmDb, loadSubDb } from '@db/index';
|
||||
import { connectRedis } from '@pubUtils/redis';
|
||||
|
||||
export default class FooBoot implements IBoot {
|
||||
@@ -17,6 +17,7 @@ export default class FooBoot implements IBoot {
|
||||
// this is the last chance to modify the config.
|
||||
await this.connectDB(this.app)
|
||||
await this.connectGMDB(this.app);
|
||||
await this.connectSubDB(this.app);
|
||||
await this.connectRedis(this.app);
|
||||
|
||||
this.app.config.realEnv = this.app.config.env;
|
||||
@@ -85,6 +86,20 @@ export default class FooBoot implements IBoot {
|
||||
}
|
||||
}
|
||||
|
||||
public async connectSubDB(app: Application) {
|
||||
const { url, options } = app.config.submongoose||app.config.mongoose
|
||||
try {
|
||||
if (url) {
|
||||
const connection = await mongoose.createConnection(url, options)
|
||||
app.context.connectionGM = connection;
|
||||
loadSubDb(connection);
|
||||
console.log('******connectSubDB suc', url, options)
|
||||
}
|
||||
} catch(e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
|
||||
public async connectRedis(app: Application) {
|
||||
const { url, pw } = app.config.redis
|
||||
if (url) {
|
||||
|
||||
@@ -16,6 +16,11 @@ export default (appInfo: EggAppInfo) => {
|
||||
options: { useNewUrlParser: true, useUnifiedTopology: true },
|
||||
};
|
||||
|
||||
config.submongoose = {
|
||||
url: 'mongodb://yjzDbOp:yjz2023ZyDB@dds-8vbc6a169e1dd6941.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbc6a169e1dd6942.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbc6a169e1dd6943.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbc6a169e1dd6944.mongodb.zhangbei.rds.aliyuncs.com:3717/zyz?replicaSet=mgset-516005504', // 内网
|
||||
options: { useNewUrlParser: true, useUnifiedTopology: true },
|
||||
};
|
||||
|
||||
config.redis = {
|
||||
url: 'r-8vbkqfcnivt4ja3ndj.redis.zhangbei.rds.aliyuncs.com', // 内网
|
||||
pw: 'hWCJ$HDajm9SN&&Z'
|
||||
|
||||
Reference in New Issue
Block a user