json - 如何通过 firebase 托管将我的主页重定向到随机 url?

标签 json firebase firebase-hosting

我正在尝试使用 Firebase 托管通过 302 重定向来重定向我的主页。

"redirects" :[{
    "source": "/",
    "destination": "what do i put here?",
    "type": 302

    }
]

在我的公用文件夹中,有index.html、404.html 和一个装满文件的文件夹。 我希望我的主页随机重定向到这些文件之一。

我知道你可以使用location.href/assign/replace在index.html中进行重定向,但我必须通过302重定向来实现。

谢谢。

最佳答案

可能的替代解决方案,涉及云功能:

在 firebase.json

"hosting": {
  "rewrites": [
    {
      "source": "**",
      "function": "randomRedirect"
    }
  ]
}

在函数的index.ts中(假设是TypeScript):

export const randomRedirect = functions.https.onRequest((_, res: functions.Response) => {
    res.redirect(302, 'your desired URL');
});

编辑:您需要删除index.html 文件才能更改地址栏中的URL。

关于json - 如何通过 firebase 托管将我的主页重定向到随机 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58479587/

相关文章:

c# - JSON.NET 部分更新 Rest API 客户端

iOS 空 Firebase 推送通知不显示

android - Crashlytics 在应用程序启动时因 Resources$NotFoundException 而崩溃

javascript - 在本地运行 Firebase

node.js - 在 Firebase 托管上安装 NPM 依赖项

firebase - Firebase 云功能没有 CDN 缓存命中

java - 错误 :java. io.FileNotFoundException

c# - 使用 2 个非默认构造函数反序列化类

json - 从 JSON Api 快速请求数据

firebase - 查询与空字段的比较