在 firebase 函数中,获取当前的 https://domain 部分

Yuk*_*oue 3 node.js express firebase google-cloud-functions

我正在编写一个 firebase 函数,以便它将根据请求路径/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))
})
Run Code Online (Sandbox Code Playgroud)

当我重写此函数的每个源时,/colletion/1path我访问https://MY-PROJECT.firebaseapp.com/collection/1.

我不知道如何才能获得该MY-PROJECT.firebaseapp.com零件。

我拿来了req.domain,但它是null

任何想法?

Dou*_*son 6

由于 HTTPS 函数由 Express 提供服务(并接收快速请求对象作为参数,因此您需要将请求hostname与请求一起使用protocol来构建可能对调用者有帮助的 URL。这些都是参数的req属性在您给定的代码中,它是一个Express Request 对象