如何获取要在Firebase云功能中使用的Firebase项目区域值

我在两个不同的位置创建了2个项目。例如us-central1和Asia-northeast1。 现在,对于这两个不同的项目,我想在各自的区域中部署云功能。

const function_location = 'asia-northeast1';// I want a region of the project selected through npm 
exports.Addweblogs = functions.region(function_location).firestore.document(............

如何在环境变量或process.env中的某个位置获取项目区域值,以便可以使用它在云函数中设置该区域。

REact_APP_API_KEY             = xyz
REact_APP_AUTH_DOMAIN         = xyz
REact_APP_DATABASE_URL        = xyz
REact_APP_PROJECT_ID          = xyz
REact_APP_STORAGE_BUCKET      = xyz
REact_APP_MESSAGING_SENDER_ID = xyz
janwen2010 回答:如何获取要在Firebase云功能中使用的Firebase项目区域值

如果我正确理解了您的问题,则您有两个项目:Project A位于us-central1中,而Project B位于asia-northeast1中。您想知道它们各自的区域,并将其存储在一个环境变量中,以便稍后在部署Cloud Function时使用。

  

see what your default region and zone settings are in your project,您可以使用云命令行工具:

gcloud compute project-info describe --project [PROJECT_ID]

  

set a variable using the gcloud command-line tool,请在部署时使用--set-env-vars标志:

gcloud functions deploy FUNCTION_NAME --set-env-vars myRegion=region

  

您可以access your environment variable at runtime。在运行时,可以通过Node.js中的process.env属性访问环境变量:

gcloud functions deploy envVar --runtime nodejs10 --set-env-vars myRegion=region --trigger-http
  

然后,您可以使用:

exports.envVar = (req,res) => {
  // Sends 'region' as response
  res.send(process.env.myRegion);
};

希望这会有所帮助。

本文链接:https://www.f2er.com/3146093.html

大家都在问