简体   繁体   English

如何从 React App 访问 Google Cloud Run 环境变量

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

I have Cloud Run environment variables as defined for my Google Cloud Run React App deployment.我有为我的 Google Cloud Run React App 部署定义的 Cloud Run 环境变量。

在此处输入图像描述

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.但是我应该如何从 Google Cloud Run 仪表板获取环境变量并传播到客户端而不依赖“.env”文件。

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.如果你想在你的 react 应用程序中使用这些变量(process.env.REACT_APP_BASE_FRONTEND_URL、process.env.REACT_APP_BASE_BACKEND_URL),那么你必须创建一个 .env 文件,该文件将包含你的 react 应用程序的所有环境变量,因为提供这个的库名为dotenv的默认配置可以从 .env 文件中获取所有这些环境变量。

So you have to get those env variables from Google cloud and paste them into .env file, then the issue should be solved.所以你必须从谷歌云中获取这些环境变量并将它们粘贴到 .env 文件中,然后问题应该得到解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 REACT APP 无法访问谷歌云运行环境变量 - REACT APP not access the google cloud run environment variables 无法访问谷歌云中的环境变量(node js express app) - Unable to access environment variables in google cloud (node js express app) 如何在 Google App Engine 标准环境中使用 Google Cloud Build 或其他方法设置环境变量? - How to set environment variables using Google Cloud Build or other method in Google App Engine Standard Environment? Google App Engine:修改 Cloud Run 环境 - Google App Engine: Modify Cloud Run Environment 如何访问 React JS Web 应用程序中的环境变量? - How to access environment variables inside React JS web app? 如何从 Node 应用程序客户端访问环境变量 - How to access environment variables from Node app client 如何使用IBM Cloud Toolchain访问node js应用程序中的环境变量? - How to access environment variables in node js app using IBM Cloud Toolchain? Google App Engine:为 React Production Build 设置环境变量 - Google App Engine: Setting environment variables for React Production Build 如何从AngularJS访问Heroku上的环境变量 - How to access environment variables on Heroku from AngularJS 如何从`npm start`访问环境变量? - How to access environment variables from `npm start`?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM