【发布时间】:2018-01-17 21:58:00
【问题描述】:
我想拔头发;这要么超级简单,我脑子都冻僵了,要么没那么简单。
我想要什么
当用户转到:myapp.firebaseappurl.com/url/SHORTENEDLINK
SO 不允许我添加缩短的 URL
我希望输出是:
{
"url": "https://stackoverflow.com/questions/45420989/sphinx-search-how-to-use-an-empty-before-match-and-after-match"
}
我尝试过的
firebase.json文件:
{
"hosting": {
"public": "public",
"rewrites": [ {
"source": "/url/:item",
"destination": "/url/:item"
} ]
}
}
index.js文件:
const functions = require('firebase-functions');
exports.url = functions.https.onRequest((requested, response) => {
var uri = requested.url;
request({
uri: uri,
followRedirect: true
},
function(err, httpResponse) {
if (err) {
return console.error(err);
}
response.send(httpResponse.headers.location || uri);
}
);
});
结果
当我转到myapp.firebaseappurl.com/url/SHORTENEDLINK 时,我得到以下信息:
Error: could not handle the request
【问题讨论】:
-
在请求中添加
method : 'POST' -
为什么?传递的参数在 URL 中,所以是 GET 请求吧?
-
@mohamadrabee - 另外,只是试了一下,看看是不是这样。没有。没用。
-
对不起我的错误
-
你能分享你的 package.json 吗?您是否在依赖项中有“请求”
标签: node.js firebase google-cloud-functions firebase-hosting url-shortener