如何在 heroku 应用程序中为 google 凭据设置环境变量

How to set an environment variable for google credentials in a heroku app

我正在使用 heroku 托管使用 firebase-admin 更新 firestore 数据的快速服务器。

Google 文档说:

When authorizing via a service account, you have two choices for providing the credentials to your application. You can either set the GOOGLE_APPLICATION_CREDENTIALS environment variable, or you can explicitly pass the path to the service account key in code. The first option is more secure and is strongly recommended.

To set the environment variable:

Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the file path of the JSON file that contains your service account key. This variable only applies to your current shell session, so if you open a new session, set the variable again.

我在本地下载了包含服务帐户密钥的 JSON 文件。 google 表示避免将路径传递给代码中的服务帐户密钥。那么你实际上如何 "set the GOOGLE_APPLICATION_CREDENTIALS environment variable" 用于 heroku 服务器上的 node.js 项目 运行?一些有助于阐明其工作原理的细节也将受到赞赏。应该如何从远程服务器访问本地文件,为什么路径不安全等

尝试进入您的帐户 -> 项目 -> 设置,就像第二个声音一样 Config Vars

按下 Reveal Config Vars。您可以在此处插入 GOOGLE_APPLICATION_CREDENTIALS 变量。