Firebase Cloud功能未调用 [英] Firebase Cloud functions are not called
问题描述
当我访问"/s/:id"时,我的站点将调用函数"s".
但是,它从未真正被调用.
如Firebase项目概述所确认,没有证据表明该函数已被调用.
我不知道为什么,因为控制台中没有错误.
My site will call function "s" when I access " / s /: id".
However, it is never actually called.
As confirmed by firebase Project Overview, there is no evidence that function was called.
I don't know why because there is no error in the console.
#functions/firebase.json
{
"functions": {
"source": "functions"
},
"hosting": {
"public": "dist",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "/s/*",
"function": "s"
},
{
"source": "**",
"destination": "/index.html"
}
]
}
}
访问"s/:id"时,不调用函数,而是应用"index.html".
我知道"index.html"是首选,因为它位于"public"中,但是我认为这不是为什么不调用顶部函数的原因.
When "s /: id" is accessed, function is not called, but "index.html" is applied.
I know that "index.html" is preferred because it is in "public", but I don't think it will be the reason why the function at the top is not called.
#functions/index.js
const functions = require("firebase-functions");
const express = require("express");
const app = express();
const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
const db = admin.firestore();
const genHtml = (image_url, id) => `
<!DOCTYPE html>
<html>
<head>
//Meta tag to overwrite
</head>
<body>
<script>
location.href = '/share/${id}';
</script>
</body>
</html>
`;
app.get("s/:id", (req, res) => {
//processing
});
exports.s = functions.https.onRequest(app);
可能是什么原因?
推荐答案
通过匹配函数和数据库区域来正确响应.我不知道这是不是原因,但它如此有效地关闭了它.
Responded correctly by matching the function and database regions. I don't know if this is the cause, but it worked so close it.
这篇关于Firebase Cloud功能未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!