【问题标题】:Using environment variables in Ghost v1 config在 Ghost v1 配置中使用环境变量
【发布时间】:2018-12-05 19:25:21
【问题描述】:

在 Ghost 0.x 中,配置是通过单个 config.js 文件提供的,其中包含每个 env 的密钥。
在 Ghost 1.0 中,配置是通过多个 config.json 文件提供的

Ghost 1.0 中如何提供环境变量?

我想像这样在Cloud9 IDE 上使用 process.env.port 动态设置端口值。

config.development.json

{
  "url": "http://localhost",
  "server": {
    "port": process.env.port,
    "host": process.env.IP
  }
}

当我使用带有以下配置的ghost start 运行应用程序时,它显示您可以在http://localhost:2368 访问您的出版物,但是当我在http://c9.io 中转到http://localhost:2368 时,它给出了我的错误提示 似乎没有应用程序在此处运行!

{
  "url": "http://localhost:2368",
  "server": {
    "port": 2368,
    "host": "127.0.0.1"
  }
}

【问题讨论】:

    标签: environment-variables ghost-blog ghost c9.io


    【解决方案1】:

    我设法弄清楚如何做到这一点。

    如果其他人也想弄清楚如何做同样的事情,这是解决方案。

    在您的 config.development.json 文件中,添加以下内容。

    {
      "url": "http://{workspace_name}-{username}.c9users.io:8080",
      "server": {
        "port": 8080,
        "host": "0.0.0.0"
      }
    }
    

    或者,在终端中运行以下命令。这将动态获取端口和主机环境变量的值,并将上述内容添加到 config.development.json 文件中。

    ghost config url http://$C9_HOSTNAME:$PORT
    ghost config server.port $PORT
    ghost config server.host $IP
    

    【讨论】:

      猜你喜欢
      • 2013-05-27
      • 1970-01-01
      • 1970-01-01
      • 2019-01-25
      • 2017-09-06
      • 2020-09-28
      • 2014-08-05
      • 2022-08-13
      • 2018-09-20
      相关资源
      最近更新 更多