Yuki Inoue
Yuki Inoue

Reputation: 3777

In firebase functions, get the current https://domain part

I'm writing a firebase functions so that it will render a page based on the request path/url.

const functions = require('firebase-functions')

function buildHtml (path) {
  return HTML_BODY_WITH_path_BEING_CONSIDERED
}

export const rendering = functions.https.onRequest(function(req, res) {
  const path = req.path
  res.send(buildHtml(path))
})

When I rewrite every source to this function, I could obtain /colletion/1 as path then render the page, when I access https://MY-PROJECT.firebaseapp.com/collection/1.

What I can't figureout is how can I obtain the MY-PROJECT.firebaseapp.com part.

I fetched req.domain but it was null.

Any idea?

Upvotes: 3

Views: 1499

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317372

Since HTTPS functions are served by Express (and receive an express request object as a parameter, you'll want to use the request hostname in tandem with the request protocol to build a URL that may be helpful to the caller. These are both properties on the req parameter in your given code, which is an Express Request object.

Upvotes: 6

Related Questions