本文介绍了如何在https的firebase函数中获取托管URL而不是函数url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有动态生成的URL,需要为登台和生产环境创建这些URL.我正在混合Firebase托管和功能.我还使用Firebase配置将URL路由到我的Firebase函数"app".当我尝试在Firebase函数中使用req.get('host')访问站点时尝试获取托管URL时,我会获取函数url.如何获得托管网址? -触发firebase函数的网址?

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?

推荐答案

如果检查req.headers的内容,则会发现一些感兴趣的属性:

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

  • host:Cloud Functions的主机,例如"us-central1-YOUR-PROJECT.cloudfunctions.net:
  • x-forwarded-host:您的Firebase托管主机,例如"YOUR-PROJECT.firebaseapp.com"
  • x-forwarded-proto:原始请求的协议,例如"https"
  • x-original-url:原始请求的网址路径,例如"/测试"
  • 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"

在其中三个(以"x-"开头的)之间,您可以将它们连接在一起以获得原始URL.

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.

这篇关于如何在https的firebase函数中获取托管URL而不是函数url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 06:36