我感觉要把头发都拔光了;这可能非常简单,但我脑子一片空白,或者它并不那么简单。
我的需求
我正在尝试使用 Firebase 解除缩短的 URL。当用户访问以下网址时:
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'
添加到请求中。 - mohamad rabee