PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, August 19, 2022

[FIXED] How to access Google Cloud Run Environment Variables from React App

 August 19, 2022     environment-variables, google-cloud-run, node.js, reactjs     No comments   

Issue

I have Cloud Run environment variables as defined for my Google Cloud Run React App deployment.

enter image description here

However when I try to access them inside the react app as below, it gets "undefined" values.

export const BASE_FRONTEND_URL = process.env.REACT_APP_BASE_FRONTEND_URL
export const BASE_BACKEND_URL = process.env.REACT_APP_BASE_BACKEND_URL

I understand that the values above are in client browser, and there are no variables exist at that moment.

But how should I get the environment variables from Google Cloud Run dashboard and propagate to the client without relying on ".env" files.


Solution

If you want to use those variables (process.env.REACT_APP_BASE_FRONTEND_URL, process.env.REACT_APP_BASE_BACKEND_URL) into your react app then you have to create a .env file, which will contain all environment variables for your react app because the library which provide this named dotenv have default configuration to get all those environment variables from .env file.

So you have to get those env variables from Google cloud and paste them into .env file, then the issue should be solved.



Answered By - satydotjs
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing