怎么在没有app上下文的文件中 获取config中的配置?
- Dominant language
- TypeScript
- Stars
- 19k
- Forks
- 1.8k
- PR merge metrics
- No merged PRs in 30d
Description
### 在此输入你需要反馈的 Bug 具体信息(Bug in Detail):
1、在APP启动之前:初始化一个 数据库,但需要获取Config中的配置
2、const config = require("../config/config.default");
3、发现必须传入APPInfo。
4、觉得不太理解,为什么在设计 config 的时候 app 不能作为一个 require 选项,而非是一个参数传入。
### 可复现问题的仓库地址(Reproduction Repo)
```
const { Sequelize } = require('sequelize');
const config = require("../config/config.default"); **//问题在这, 我怎么获取里面的信息呢,现在 config 是一个function**
const sequelize = new Sequelize(config.database, config.username, config.password, {
host: config.host,
dialect: config.dialect,
});
(async () => {
try {
await sequelize.authenticate();
console.log('Connection has been established successfully.');
await sequelize.sync({ force: true });
console.log('Database synchronized successfully.');
process.exit(0);
} catch (error) {
console.error('Unable to connect to the database:', error);
process.exit(1);
}
})();
```
### Node 版本号:
22.0
### Eggjs 版本号:
3.24.1
### 相关插件名称与版本号(PlugIn and Name):
"egg": "^3.24.1", "egg-bin": "^6.10.0", "egg-ci": "^2.2.0", "egg-cors": "^3.0.1", "egg-jsonp": "^2.0.0", "egg-mock": "^5.12.0", "egg-mysql": "^4.0.0", "egg-onerror": "^2.2.0", "egg-passport": "^2.1.1", "egg-redis": "^2.6.0", "egg-scripts": "^3.0.1", "egg-sequelize": "^6.0.0", "egg-session": "^3.3.0", "egg-socket.io": "^4.1.6", "egg-validate": "^2.0.2",
### 操作平台与版本号(Platform and Version):
mac 15
Contributor guide
Assessment
This issue has not been assessed yet.