【发布时间】:2020-04-30 10:57:14
【问题描述】:
当到达我的托管网站路径时,我正在尝试触发谷歌云功能。
所以,我在我的 firebase.json 上添加了这个
"rewrites": [
{
"source": "**",
"destination": "/index.html",
"function": "app"
}
这是我的函数,名为 "app":
[...]
server.get('*', (req:any,res:any) => {
const isBot = detectBot(req.headers['user-agent']);
if(isBot) {
const botUrl = generateUrl(req);
nf(`${renderUrl}/${botUrl}`)
.then((r: { text: () => any; }) => r.text())
.then((body: { toString: () => any; }) => {
res.set('Cache-Control', 'public, max-age=300, s-maxage=600');
res.set('Vary','User-Agent');
res.send(body.toString())
});
} else {
nf(`https://${appUrl}`)
.then((r: { text: () => any; }) => r.text())
.then((body: { toString: () => any; }) => {
res.send(body.toString());
});
}
});
exports.app = functions.https.onRequest(server);
"app" 功能和网站已部署,但是当我到达一个 url 时,"app" 功能不会被触发。
提前致谢。
【问题讨论】:
标签: node.js firebase google-cloud-functions firebase-hosting