4

使用strapi 1.5.4.

是否可以使用环境变量配置strapi?如果没有,如何在不提交/公开数据库凭据和其他机密的情况下配置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"
      }
    }
  }
};
4

3 回答 3

3

看起来唯一的方法是使用钩子。在我的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();
})();
于 2016-04-19T15:56:52.227 回答
0

你可以使用这个插件来管理你的秘密:https ://github.com/cyberark/summon 上面的插件将为你的秘密值提供更多的抽象,并且它们也支持一堆提供者

于 2019-10-21T13:04:15.713 回答
0

2021 年,Strapi 提供了一个开箱即用的解决方案。

https://strapi.io/documentation/developer-docs/latest/setup-deployment-guides/configurations.html#configuration-using-environment-variables

于 2021-06-16T12:09:24.067 回答