【发布时间】:2018-10-13 20:54:58
【问题描述】:
我想要一个像https://<my-project-id>.firebaseapp.com/parameter 这样的自定义网址,这样我就有一个函数可以接收值'parameter'。
这是我对 firebase.json 重写的内容:
"rewrites": [
{
"source": "/:bar*", "function": "foo"
},
{
"source": "**",
"destination": "/index.html"
}
]
然后对于函数/index.js,这里是我的 'foo' 函数:
exports.foo = functions.https.onRequest((req, res) => {
console.log('bar = '+req.query.bar);
console.info(req.query.bar);
res.status(200).send(`<!doctype html>
<head>
<title>Test</title>
</head>
<body>
Bar = ${req.query.bar}
</body>
</html>`);
});
什么有效,但不是我想要的
如果我将 firebase.json 更改为以下内容:
"rewrites": [
{
"source": "/**", "function": "foo"
},
{
"source": "**",
"destination": "/index.html"
}
]
把网址写成这样:
https://<my-project-id>.firebaseapp.com/anything?bar=test
然后它正确地获取 bar 参数。但是,我需要能够缩短 url。
【问题讨论】:
标签: node.js firebase google-cloud-functions firebase-hosting