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
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 has documentation on <a href="https://firebase.google.com/docs/functions/config-env" rel="nofollow">adding environmental configurations to Firebase Functions</a> such that I can add key/value pairs to be accessed at runtime from within a firebase <strong>function</strong>:
firebase functions:config:set mySecret.key="CLIENT_ID" mySecret.id="secret_here"
however <strong>I am unclear how added configuration variables can be accessed from Firebase-hosted static applications (rather than functions).</strong>
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_IDAnswer1:
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.
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.Answer2:
The best practice way to handle what I am trying to do is to refactor all of the application logic requiring environment configuration into firebase functions. I can then invoke said functions to reference environment config and execute the code consuming them. This is the answer/solution I needed and didn't have the context to realize earlier. thanks for edging me towards that realization.