【发布时间】:2017-08-26 00:37:12
【问题描述】:
我正在尝试为我的移动应用创建下载端点。该应用程序可在应用商店和 Play 商店中使用。我想要一个可供用户在 iOS 设备或 Android 设备上下载应用程序的 URL。我试图找出是否可以为此目的为 firebase 创建一个云功能。我正在考虑检查user-agent 的请求,并根据请求是来自iOS 设备还是Android 设备还是Web 浏览器,将用户重定向到适当的URL。我已验证user-agent 标头中存在设备信息。例如
"user-agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 10_2 like Mac OS X) AppleWebKit/602.3.12 (KHTML, like Gecko) Version/10.0 Mobile/14C89 Safari/602.1 AppEngine-Google; (+http://code.google.com/appengine; appid: s~gcf-http-proxy)"
我猜接下来要做的是在上述情况下将用户重定向到应用商店 URL。我尝试使用res.redirect,但这不起作用。这最终会将用户重定向到cloud-function-base-url/redirect-url,而不仅仅是redirect-url。
下面是云函数的代码,当从浏览器触发该函数时,它只是试图重定向到 www.google.com。
exports.appDownload = functions.https.onRequest((req, res) => {
console.log(stringify(req.headers))
// This will eventually redirect to a store URL based on the phone in user-agent
res.redirect('www.google.com');
});
这最终将浏览器重定向到base-url/www.google.com 而不仅仅是www.google.com,并且我收到一条错误消息说Not Found。我想将浏览器重定向到 www.google.com。
我想检查是否可以使用firebase的云功能来实现上述目标。
【问题讨论】:
-
请显示您的代码不能按您预期的方式工作。
-
抱歉,如果我从浏览器调用云功能,我只是想检查是否可以将浏览器重定向到不同的 URL(在我的例子中是应用商店 URL)。我已经发布了我尝试过的代码。
标签: firebase google-cloud-functions