【问题标题】:How to store / access strapi dynamic/custom database config?如何存储/访问strapi动态/自定义数据库配置?
【发布时间】:2020-04-25 11:55:26
【问题描述】:

我是开发新手,但到目前为止很喜欢它。

在 Strapi 中创建/使用自定义数据库配置时遇到一些挑战。不太明白这里的指南:https://strapi.io/documentation/3.0.0-beta.x/concepts/configurations.html#usage

尝试创建一个 .env 文件并按照一些教程示例创建一个包含该文件的 .tmp 文件夹,但怀疑它是否正确。

Screenshot of the files and folders

【问题讨论】:

    标签: strapi


    【解决方案1】:

    我不确定你要做什么,但这里有一个关于这个主题的 GitHub 上的帖子。

    https://github.com/strapi/strapi/issues/3558

    【讨论】:

      【解决方案2】:

      Strapi 不会自动为您加载环境文件。如果您希望这样做,请创建一个引导文件 - 这将在strapi 启动时执行。为此,您需要安装dotenvnpm install --save dotenv

      // yourrepo/api/config/functions/bootstrap.js
      /**
       * An asynchronous bootstrap function that runs before
       * your application gets started.
       *
       * This gives you an opportunity to set up your data model,
       * run jobs, or perform some special logic.
       */
      
      const dotenv = require('dotenv').config(); // load environment variables
      
      
      module.exports = async () => {}
      
      

      有很多方法可以做到这一点,但为了理智起见,使用 env 文件会使您在本地设置中更容易。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-11-04
        • 1970-01-01
        • 2018-08-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多