我想在另一个 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/