如何从Firebase托管的应用程序中引用Firebase Functions配置变量? [英] How to reference Firebase Functions config variables from a Firebase-hosted application?

查看:67
本文介绍了如何从Firebase托管的应用程序中引用Firebase Functions配置变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Heroku托管的ReactJS/NodeJS应用程序转换为要在Firebase上托管.因为Firebase仅处理静态页面,所以我需要重新配置如何配置开发,登台,生产环境的专用于环境的私有变量.例如,在我定义以下种类的变量之前:

I am transitioning a Heroku-hosted ReactJS/NodeJS application to be hosted on Firebase. Because Firebase only handles static pages I need to reconfigure how my private environmental-specific variables for Development, Staging, Production environments are configured. For example before I defined these sorts of variables:

CLIENT_ID=secret_here       
DOMAIN=secret_here    
REDIRECT_URI=secret_here   

在我要部署到的Heroku环境上,现在必须从Firebase CLI将它们设置为Firebase功能环境以进行开发,登台和生产.

upon the Heroku environment I was deploying to and now I must set them into firebase functions environments from the Firebase CLI for Dev, Staging and Production.

Firebase上有有关向Firebase功能添加环境配置的文档,可以在运行时从firebase 功能中添加键/值对:

Firebase has documentation on adding environmental configurations to Firebase Functions such that I can add key/value pairs to be accessed at runtime from within a firebase function:

firebase functions:config:set mySecret.key="CLIENT_ID" mySecret.id="secret_here"

但是我不清楚如何从Firebase托管的静态应用程序(而不是函数)访问添加的配置变量.

是否像从我的应用程序中引用firebase函数库并从我的应用程序中检索已定义的键一样简单?

Is it as simple as simply referencing the firebase functions library from my application and retrieving the defined key from within my application (like so)?

const functions = require('firebase-functions');
...
functions.config().auth0.CLIENT_ID

推荐答案

通过提供的链接定义的变量仅可通过Cloud Functions使用.它们不能直接用于Firebase Hosting提供的静态内容.

The variables you define through the link you provided are only available via Cloud Functions. They're not made available directly to the static content served by Firebase Hosting.

如果需要,可以使HTTP函数不执行任何操作,只从环境变量中返回JSON,然后从Web内容中调用它.请记住,您正在向世界公开您的秘密密钥.

If you want, you can make an HTTP function that does nothing but return the JSON from your env vars, and call that from your web content. Bear in mind that you're exposing your secret keys to the world.

这篇关于如何从Firebase托管的应用程序中引用Firebase Functions配置变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆