【问题标题】:Access json file heroku访问json文件heroku
【发布时间】:2020-04-14 11:59:43
【问题描述】:

我正在尝试使用我的 Github 中的 Heroku 部署我的应用程序。 我将我的 dotenv 值放在配置变量中,但一个值引用了一个 json 文件,heroku 无法访问该文件

GCS_KEYFILE = file.json

这是json:

{
  "type": "service_account",
  "project_id": "",
  "private_key_id": "",
  "private_key": "=\n-----END PRIVATE KEY-----\n",
  "client_email": "",
  "client_id": "",
  "auth_uri": "",
  "token_uri": "",
  "auth_provider_x509_cert_url": "",
  "client_x509_cert_url": "
}

如何让 heroku 访问该文件?

更新

我尝试了下面的答案,但对我不起作用。在配置变量中,我尝试添加 json。现在我收到以下错误消息:

2020-04-14T14:40:53.370477+00:00 app[web.1]: Error: Could not authenticate request
2020-04-14T14:40:53.370493+00:00 app[web.1]: ENOENT: no such file or directory, open '/app/{
type": "service_account",
  "project_id": "",
  "private_key_id": "",
  "private_key": "=\n-----END PRIVATE KEY-----\n",
  "client_email": "",
  "client_id": "",
  "auth_uri": "",
  "token_uri": "",
  "auth_provider_x509_cert_url": "",
  "client_x509_cert_url": "
2020-04-14T14:40:53.370500+00:00 app[web.1]: at /app/node_modules/gcs-resumable-upload/build/src/index.js:235:19
2020-04-14T14:40:53.370501+00:00 app[web.1]: at /app/node_modules/google-auto-auth/index.js:27:9
2020-04-14T14:40:53.370501+00:00 app[web.1]: at /app/node_modules/google-auto-auth/index.js:233:9

这是我尝试以下答案时的错误消息:

Error: You have to specify credentials key file for Google Cloud Storage to work.

我尝试部署的代码可以找到here

【问题讨论】:

    标签: json heroku deployment


    【解决方案1】:

    Heroku 没有给你一个文件系统,所以这不是微不足道的。
    看起来有一个使用 heroku-google-application-credentials-buildpack 的workaround,但我已经用不同的方式解决了这个问题:我将我的应用程序打包在一个 Docker 映像中(其中包括它期望的 JSON 文件)并推送/部署到 Heroku。

    json 文件(包含敏感信息)不在我的代码库中,它仅在构建映像时推送到映像中。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2012-09-27
      • 1970-01-01
      • 2022-01-24
      • 1970-01-01
      • 2013-03-23
      • 1970-01-01
      • 2020-11-29
      • 2022-01-10
      • 1970-01-01
      相关资源
      最近更新 更多