【问题标题】:Firebase hosting redirect to another subdomain keeping query and paramsFirebase 托管重定向到另一个保留查询和参数的子域
【发布时间】:2022-07-06 05:49:11
【问题描述】:
如何将调用重定向到另一个子域,同时使用 Firebase 托管将所有请求保持为原始请求。我可以在 Web 应用程序级别执行此操作,但这会导致性能问题。
例如:
https://some.app.com/route/param?=something&others
到
https://different.app.com/route/param?=something&others
【问题讨论】:
标签:
firebase
redirect
firebase-hosting
【解决方案1】:
我正在做类似的事情,这是我目前作为 firebase 节点功能的尝试:
exports.redirectExample = functions.https.onRequest((req, res) => {
const redirectDomain = "example.org";
const subdomains = req.subdomains;
if (subdomains) {
const reverseJoinSubdomains = subdomains.reverse().join('.');
res.redirect("https://" + reverseJoinSubdomains + "." + redirectDomain + req.path);
} else {
res.redirect("https://" + redirectDomain + req.path);
}
});