firebase - 在代码中获取 firebase 的另一个 http 云函数的 url

标签 firebase google-cloud-functions

我想在另一个 firebase 云函数中获取 firebase 的 http 云函数的 url,而不是对其进行硬编码。是否可以?

这行不通,但是有什么方法可以做类似的事情吗?

exports.helloWorld = functions.https.onRequest((req, res) => {
    res.send("Hello!");
});

exports.anotherFunction = functions.https.onRequest((req, res) => {
    const url = exports.helloWorld.url;
    res.send(url); // https://us-central1-project-id.cloudfunctions.net/helloWorld
});     

最佳答案

由于这两个函数在同一个项目中,它们在 URL 中的主机名总是相同的。我只是让客户假设这个事实是真实的,并让另一个函数简单地返回“helloWorld”。然后,客户端可以通过将该路径附加到他们已经用于访问 anotherFunction 的主机名来组成 helloWorld 函数的完整 URL。

关于firebase - 在代码中获取 firebase 的另一个 http 云函数的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43226710/

相关文章:

swift - 如何从另一个 View Controller 中关闭 View Controller

javascript - Firebase函数: manipulate admin.数据库.ServerValue.TIMESTAMP

ios - 在 SpriteKit 中添加 FirebaseApp.configure() 的位置

javascript - Firestore 突然出现巨大的触发延迟

node.js - Firebase 函数 : how best to await unblocking promises after response is sent?

java - 在 Firestore 中仅运行 onAdd 监听器

c# - 使用 Unity 进行 Firebase 电话身份验证

python - Google 函数超出内存

node.js - 推送到 firebase 数据库时如何设置推送键?

javascript - 带有子集合的 Firestore 查询