【发布时间】:2020-07-13 07:00:05
【问题描述】:
我尝试通过在 firebase 中设置环境配置来将我的 api 密钥存储为环境变量。
这是参考https://firebase.google.com/docs/functions/config-env。
我在 Node 8 中重新部署了函数,并且在运行 firebase functions:config:get 时可以看到输出的 JSON api 密钥。
"myservice":{
"key": "******",
"id": "******"
}
但是,当我运行我的应用程序(TypeScript)并尝试测试是否可以获得我的 apikey 时:
import * as admin from "firebase-admin";
import * as functions from "firebase-functions";
import "firebase-functions";
admin.initializeApp();
const key = functions.config().myservice.key;
console.log(key);
我明白了
Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail
TypeError: Cannot read property 'key' of undefined
在控制台中看不到密钥
有人有同样的问题吗? 谁能给出一些提示来解决这个问题。谢谢。
【问题讨论】:
标签: node.js firebase environment-variables api-key