node.js - 在 firebase 函数中,获取当前的 https://domain 部分
问题描述
我正在编写一个 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))
})
当我将每个源代码重写为此函数时,我可以/colletion/1
在path
访问https://MY-PROJECT.firebaseapp.com/collection/1
.
我想不通的是如何获得MY-PROJECT.firebaseapp.com
零件。
我取了req.domain
,但它是null
。
任何想法?
解决方案
由于 HTTPS 功能由 Express 提供(并接收一个 express 请求对象作为参数,因此您需要将请求hostname
与请求一起使用protocol
来构建可能对调用者有帮助的 URL。这些都是req
参数上的属性在您给定的代码中,这是一个Express Request 对象。
推荐阅读
- java - 如何配置 RSAKey.Builder 以生成没有空值的简单结果
- flutter - (Flutter) 如何正确使用 Consumer 和 ChangeNotifierProvider ?找不到丢失的东西
- javascript - 如何在 html 的画布元素中添加两个图像 ..?
- kotlin - TabLayoutMediator 从 kotlin 到 java
- reporting-services - SSRS 添加带有字段 URL 的超链接
- ios - 表视图项目未显示
- javascript - 如果另一个 div 包含某些单词,则更改按钮上的文本
- python - Python:并非所有参数都在 SQL 语句中使用
- azure - 无法连接到 AAS - Azure 分析服务器的实际群集终结点解析失败
- linux - 删除查找结果中的文件