egg
egg copied to clipboard
如何让应用的configWillLoad在egg-sequelize建立连接之前执行
相关环境信息
-
Egg 版本:2.27.0
需求是这样的,在sequelize初始化之前,修改配置文件里的加密密码
我的应用
app.js
是这样的
class AppBoot{
constructor(app){
this.app = app;
this.ctx = app.createAnonymousContext();
}
configWillLoad(){
const {
sequelize,
redis
} = this.app.config;
const base64Reg = /^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$/;
const mysqlPwd = sequelize.password;
if(mysqlPwd && base64Reg.test(mysqlPwd)) sequelize.password = this.ctx.helper.decryptPwd(mysqlPwd);
if(redis.client && redis.client.password && base64Reg.test(redis.client.password)){
const redisPwd = redis.client.password;
redis.client.password = this.ctx.helper.decryptPwd(redisPwd);
}
}
}
如果是想异步获取远程配置的话,参考下 https://github.com/atian25/egg-remote-config
如果是想异步获取远程配置的话,参考下 https://github.com/atian25/egg-remote-config
我这里修改配置是同步的,但是貌似configWillLoad
在egg-sequelize的beforeStart之后执行了
如果是想异步获取远程配置的话,参考下 https://github.com/atian25/egg-remote-config
egg-sequelize: V5.2.1。egg:V2.26.0。
egg-sequelize在egg-remote-config前执行了
n
有解决吗?试了下remoteConfig 和 AppBootHook configWillLoad 都是在sequelize初始化后执行的
n
有解决吗?试了下remoteConfig 和 AppBootHook configWillLoad 都是在sequelize初始化后执行的
我的解决方案是复制一份egg-sequelize
插件,移除里面的agent.js