admin管理员组文章数量:1406063
Using strapi 1.5.4
.
Is it possible to configure strapi with environment variables? If not, how do you configure strapi without mitting/exposing your database credentials and other secrets?
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"
}
}
}
};
Using strapi 1.5.4
.
Is it possible to configure strapi with environment variables? If not, how do you configure strapi without mitting/exposing your database credentials and other secrets?
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"
}
}
}
};
Share
Improve this question
edited Apr 19, 2016 at 15:35
Stan Bondi
asked Apr 19, 2016 at 15:19
Stan BondiStan Bondi
4,6363 gold badges27 silver badges36 bronze badges
3 Answers
Reset to default 3Looks 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)
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();
})();
You can use this plugin to manage your secrets: https://github./cyberark/summon The above plugin will provide more abstraction on your secret values, and they are supported bunch of providers too.
In 2021 Strapi offers a solution for this out of the box.
https://strapi.io/documentation/developer-docs/latest/setup-deployment-guides/configurations.html#configuration-using-environment-variables
本文标签: javascriptStrapiConfigure with environment variablesStack Overflow
版权声明:本文标题:javascript - Strapi - Configure with environment variables - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744963326a2634789.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论