Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何让应用的configWillLoad在egg-sequelize建立连接之前执行 #4524

Open
brucewar opened this issue Nov 20, 2020 · 6 comments
Open
Assignees
Labels

Comments

@brucewar
Copy link

相关环境信息

  • 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);
    }
  }
}
@atian25
Copy link
Member

atian25 commented Nov 20, 2020

如果是想异步获取远程配置的话,参考下 https://github.com/atian25/egg-remote-config

@brucewar
Copy link
Author

如果是想异步获取远程配置的话,参考下 https://github.com/atian25/egg-remote-config

我这里修改配置是同步的,但是貌似configWillLoad在egg-sequelize的beforeStart之后执行了

@Imfdj
Copy link

Imfdj commented Nov 24, 2020

如果是想异步获取远程配置的话,参考下 https://github.com/atian25/egg-remote-config

image
egg-sequelize: V5.2.1。egg:V2.26.0。
egg-sequelize在egg-remote-config前执行了

@wood-liu92
Copy link

n

有解决吗?试了下remoteConfig 和 AppBootHook configWillLoad 都是在sequelize初始化后执行的

@brucewar
Copy link
Author

brucewar commented Feb 9, 2022

n

有解决吗?试了下remoteConfig 和 AppBootHook configWillLoad 都是在sequelize初始化后执行的

我的解决方案是复制一份egg-sequelize插件,移除里面的agent.js
image
image

@fengmk2
Copy link
Member

fengmk2 commented Dec 11, 2024

eggjs/core#272 类似的需求

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants