[英]Question regarding returning a null value in a then callback of a promise in firebase cloud functions
[英]Firebase callable functions. Promise is returning null on the client ( Cloud Functions )
我开发了这个 firebase 函数来从我的应用程序搜索 (elastic) 中返回数据。 当我在函数控制台上记录它时,我可以看到请求数据,我还可以在我的 App Search API 日志中看到响应正文。 但我无法在客户端获取数据
{
"meta": {
"alerts": [],
"warnings": [],
"precision": 2,
"page": {
"current": 1,
"total_pages": 1,
"total_results": 2,
"size": 10
},
"engine": {
"name": "engine",
"type": "default"
},
"request_id": "DF4VEuzuQpWAHH8VCBkvDg"
},
"results": [
{
"nome": {
"raw": "Produto legal"
},
"_meta": {
"engine": "engine",
"score": 0.8957006,
"id": "bnxvuzVXIQ4BxqHxjvgt"
},
"id": {
"raw": "bnxvuzVXIQ4BxqHxjvgt"
}
},
{
"nome": {
"raw": "Produto massa"
},
"_meta": {
"engine": "engine",
"score": 0.3164503,
"id": "rdG192xjSVCLIEBNg0la"
},
"id": {
"raw": "rdG192xjSVCLIEBNg0la"
}
}
]
}
exports.searchProdutos = functions.https.onCall((data, context) => {
const options = {
search_fields: { nome: {} },
result_fields: { nome: { raw: {} } },
};
const query = data.query;
client
.search("engine", `${query}`, options)
.then((response) => {
return response;
})
.catch((error) => console.log(error.errorMessages));
});
但是当我尝试在客户端调用它并记录响应时,我在控制台中记录了两个空对象
const searchProdutos = httpsCallable(functions, "searchProdutos");
const getProdutos = async () => {
const results = await searchProdutos({ query: "produto" });
console.log(results.data);
};
getProdutos();
附加信息:我在我的函数中使用 Nodejs App Search 并作为我的前端库/框架做出反应
编辑:我也收到了 200 条回复。 所以我想这个请求没有任何问题。 我尝试从我的客户端函数中删除 .then 但我仍然收到data: {null}
两次
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.