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?
Firebase Hosting is production-grade web content hosting for developers. With a single command, you can quickly deploy web apps and serve both static and dynamic content to a global CDN (content delivery network).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With