How can I get the hosting url instead of functions url in firebase functions for https

别说谁变了你拦得住时间么 提交于 2020-06-25 21:55:29

问题


I have dynamically generated urls that I need to create for staging and production environments. I am doing a mix of Firebase hosting and functions. I am also using Firebase config to route urls to my Firebase functions "app". When I try to get the hosting url when I visit my site with req.get('host') inside a Firebase function I get the functions url. How can I get the Hosting url? - the url that triggered the firebase function?


回答1:


If you examine the contents of req.headers, you'll find some attributes of interest:

  • host: The host of Cloud Functions, e.g. "us-central1-YOUR-PROJECT.cloudfunctions.net:
  • x-forwarded-host: Your Firebase Hosting host, e.g. "YOUR-PROJECT.firebaseapp.com"
  • x-forwarded-proto: The protocol of the original request, e.g. "https"
  • x-original-url: The URL path of the original request, e.g. "/test"

Between three of those (the ones that start with "x-"), you could concatenate them together to get the original URL.

I don't know if these headers are fully documented and supported.




回答2:


As far as I know the original URL that the user typed is not available in the request that you get in Cloud Functions. The rewrite happens on a different server, and no information is passed along.



来源:https://stackoverflow.com/questions/51195552/how-can-i-get-the-hosting-url-instead-of-functions-url-in-firebase-functions-for

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