[英]Strapi - Configure with environment variables
Using strapi 1.5.4
.使用
strapi 1.5.4
。
Is it possible to configure strapi with environment variables?是否可以使用环境变量配置trapi? If not, how do you configure strapi without committing/exposing your database credentials and other secrets?
如果没有,您如何在不提交/公开您的数据库凭据和其他机密的情况下配置 Strapi?
module.exports = {
"orm": {
"adapters": {
"disk": "sails-disk",
"mysql": "sails-mysql"
},
"defaultConnection": "default",
"connections": {
"default": {
"adapter": "disk",
"filePath": ".tmp/",
"fileName": "default.db",
"migrate": "alter"
},
"permanent": {
"adapter": "mysql",
"user": process.env.DB_USER,
"password": process.env.DB_PASSWORD,
"migrate": "alter"
}
}
}
};
Looks like the only way is to use a hook. 看起来唯一的方法是使用钩子。 In my
server.js
file (I would move the config into it's own file and clean this up) 在我的
server.js
文件中(我会将配置移到它自己的文件中并清理)
const orm = {
"adapters": {
"disk": "sails-disk",
"mysql": "sails-mysql"
},
"defaultConnection": "default",
"connections": {
"default": {
"adapter": "disk",
"filePath": ".tmp/",
"fileName": "default.db",
"migrate": "alter"
},
"permanent": {
"adapter": "mysql",
"user": process.env.DB_USER || 'root',
"password": process.env.DB_PASSWORD || 'password',
"database": process.env.DB_NAME || 'test',
"host": "127.0.0.1",
"migrate": "alter"
}
}
};
(function () {
const strapi = require('strapi');
// Use a hook to override the config
strapi.on('hook:_config:loaded', () => {
strapi.config.orm = orm;
});
strapi.start();
})();
您可以使用此插件来管理您的机密: https : //github.com/cyberark/summon上面的插件将提供有关您的机密值的更多抽象,它们也受一堆提供程序的支持。
In 2021 Strapi offers a solution for this out of the box. 2021 年,Strapi 为此提供了一个开箱即用的解决方案。
https://strapi.io/documentation/developer-docs/latest/setup-deployment-guides/configurations.html#configuration-using-environment-variables https://strapi.io/documentation/developer-docs/latest/setup-deployment-guides/configurations.html#configuration-using-environment-variables
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.