In your code add some logic to switch between envs eg
import'firebase/analytics';import firebase from'firebase/app';import'firebase/auth';import'firebase/firestore';import'firebase/functions';import'firebase/storage';constFIREBASE_CONFIG_DEV= { apiKey:process.env.REACT_APP_API_KEY_DEV, authDomain:process.env.REACT_APP_AUTH_DOMAIN_DEV, databaseURL:process.env.REACT_APP_DATABASE_URL_DEV, projectId:process.env.REACT_APP_PROJECT_ID_DEV, storageBucket:process.env.REACT_APP_STORAGE_BUCKET_DEV, messagingSenderId:process.env.REACT_APP_MESSAGING_SENDER_ID_DEV, appId:process.env.REACT_APP_APP_ID_DEV, measurementId:process.env.REACT_APP_MEASUREMENT_ID_DEV,};constFIREBASE_CONFIG_UAT= { apiKey:process.env.REACT_APP_API_KEY_UAT, authDomain:process.env.REACT_APP_AUTH_DOMAIN_UAT, projectId:process.env.REACT_APP_PROJECT_ID_UAT, storageBucket:process.env.REACT_APP_STORAGE_BUCKET_UAT, messagingSenderId:process.env.REACT_APP_MESSAGING_SENDER_ID_UAT, appId:process.env.REACT_APP_APP_ID_UAT, measurementId:process.env.REACT_APP_MEASUREMENT_ID_UAT,};constFIREBASE_CONFIG_PROD= { apiKey:process.env.REACT_APP_API_KEY_PROD, authDomain:process.env.REACT_APP_AUTH_DOMAIN_PROD, databaseURL:process.env.REACT_APP_DATABASE_URL_PROD, projectId:process.env.REACT_APP_PROJECT_ID_PROD, storageBucket:process.env.REACT_APP_STORAGE_BUCKET_PROD, messagingSenderId:process.env.REACT_APP_MESSAGING_SENDER_ID_PROD, appId:process.env.REACT_APP_APP_ID_PROD, measurementId:process.env.REACT_APP_MEASUREMENT_ID_PROD,};// Initialize Firebaseif (process.env.REACT_APP_NODE_ENV.toLowerCase() ==='dev') {firebase.initializeApp(FIREBASE_CONFIG_DEV);} elseif (process.env.REACT_APP_NODE_ENV.toLowerCase() ==='uat') {firebase.initializeApp(FIREBASE_CONFIG_UAT);} elseif (process.env.REACT_APP_NODE_ENV.toLowerCase() ==='prod') {firebase.initializeApp(FIREBASE_CONFIG_PROD);} else {// firebase.initializeApp(FIREBASE_CONFIG_DEV);console.error('ENVs not set correctly');}exportconstdb=firebase.firestore();exportconstfunctions=firebase.functions();exportconstanalytics=firebase.analytics();exportconststorage=firebase.storage();// https://stackoverflow.com/questions/50884534/how-to-test-functions-https-oncall-firebase-cloud-functions-locally// TODO: add condition that if in dev, then use emulator for functions// firebase.functions().useFunctionsEmulator('http://localhost:4001');exportdefault firebase;
you can then build the CRA app in different
dev
prod
uat
npx cross-env REACT_APP_NODE_ENV=dev npm run build
Optional other services
5. Google Cloud task
5.1 Setup a google cloud task for each env
Enable cloud task API for all 3 envs from GCP dashboard for these firebase projects
Eg the google cloud task coul be used by the an STT cloud function
5.2 Create a google queue
Create a Google Queue to use with the cloud task (for all 3 envs)
Create a Google Queue (eg firestore-stt) to use Google Task within this project. This is for using GCP STT with firebase cloud functions. See architecture diagram for more info.
Set the Firebase web API key as env var for cloud functions, to be able to use to call the GCP STT operation end point, outside of the STT SDK to check progress of a transcription.
firebase functions:config:set webapi.key="THE FIREBASE WEB API KEY"
more info here
This could be used by a cloud function to retrieve data from a STT operation eg