How to access environment-specific Firebase Function endpoints from Firebase Hosted application?

好久不见. 提交于 2019-12-04 05:50:27

问题


I have three Firebase projects representing Development, Staging and Production environments hosted on Firebase hosting. Each environment utilizes its own deployed Firebase functions like so:

  • Dev function endpoint: https://us-central1-my-app-dev.cloudfunctions.net/someFunction
  • Staging function endpoint: https://us-central1-my-app-staging.cloudfunctions.net/someFunction
  • Production function endpoint: https://us-central1-my-app.cloudfunctions.net/someFunction

I can't figure out how the static, Firebase-hosted client React application should invoke these functions because the URI endpoints of each changes depending on which environment the code is executing from.

Ideally I could set environment-specific configuration for each Firebase Hosting environment; unfortunately the only way to do this in Firebase Hosting is from within Firebase Functions themselves.

How can I retrieve the environment-specific endpoint for each Firebase Function?


回答1:


You have a couple options here.

First, you could just configure your React app any way you like. It's necessarily not a bad thing for each system component (backend, frontend) to have its own configuration.

Second, since you're using Firebase Hosting to serve your static content, you can also use it to serve your functions API endpoints. This means that both your static content and API endpoints are all served through the same hostname, which means you no longer have to specify the host when making a request. All the requests can be relative to that host. You can achieve this via Hosting rewrite rules.



来源:https://stackoverflow.com/questions/49054860/how-to-access-environment-specific-firebase-function-endpoints-from-firebase-hos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!