【问题标题】:Set Firebase local emulator cloud function environment config values设置 Firebase 本地模拟器云功能环境配置值
【发布时间】:2019-07-08 10:45:50
【问题描述】:

更新云函数环境变量时,使用本地 node.js 模拟器时无法访问配置值。

在没有环境配置变量的项目上:

  • 设置新值firebase functions:config:set x=true
  • 获取配置变量firebase functions:config:get(显示新值)
  • 部署函数firebase deploy --only functions
  • 运行本地模拟器并注销functions.config{}
  • 输出:{}(空对象)

environment config docs 中没有提及,但我假设可以在本地(或本地替代)使用相同的环境配置?

【问题讨论】:

    标签: node.js firebase google-cloud-functions


    【解决方案1】:

    答案在local emulator documentation

    注意:您可以检索您的生产自定义配置变量 模拟功能时。但是,在使用生产时要小心 在 API 调用、电子邮件等的本地测试中配置值。

    要使用配置变量,请在函数中运行以下命令 运行 firebase serve 之前的目录。

    MacOS

    firebase functions:config:get > .runtimeconfig.json

    Windows

    firebase functions:config:get | ac .runtimeconfig.json

    【讨论】:

    • 警告:由于 JSON 之前存在不可见字符的问题,上述命令不适用于 Windows Powershell。如果使用 Powershell,请改用 firebase functions:config:get | ac .runtimeconfig.json
    • 另外,.runtimeconfig.json 必须在函数文件夹中。
    • 此文档已被重新编写。不确定这里提出的解决方案是否真的解决了最初的问题,但不幸的是现在它肯定不再这样做了。
    • 将其放入功能文件夹后为我工作。 @twiz 文件内容是您之前使用 functions:config:set 设置到您的云实例的任何值。它只是一个 js 对象的 json。例如 { "key": 123 }
    • 如果.runtimeconfig.json 包含敏感密钥,请注意将.runtimeconfig.json 从部署中排除在firebase.json > functions > ignore.gitignore 中。 .runtimeconfig.json 记录在这里:firebase.google.com/docs/functions/…
    猜你喜欢
    • 2018-01-30
    • 2021-08-22
    • 1970-01-01
    • 2019-02-21
    • 2021-02-26
    • 2020-03-18
    • 2018-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多