【问题标题】:firebase hosting not displaying the correct file contentsfirebase 托管未显示正确的文件内容
【发布时间】:2019-07-21 19:39:26
【问题描述】:

我正在尝试在 firebase 上为 PWA 托管一个assetlinks.json 文件,问题是我无法查看文件的内容。我认为这与我的 firebase.json 文件有关。我试图获得的链接是 https://bionomichealth.com/.well-known/assetlinks.json 它包含:

    [
  {
    "relation": ["delegate_permission/common.handle_all_urls"],
    "target": {
      "namespace": "android_app",
      "package_name": "xyz.appmaker.flvhwm",
      "sha256_cert_fingerprints": ["83:AE:08:45:58:C6:08:16:69:1E:80:50:31:84:1E:B9:55:AF:CC:4F:A9:20:B3:D5:58:B1:6A:D1:E1:27:B3:F7"]
    }
  }
]

最后,这是我的 filebase.json:

    {
  "database": {
    "rules": "database.rules.json"
  },
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint",
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ]
  },
  "hosting": {
    "public": "public",
    "rewrites": [
      {
        "source": "/.well-known/assetlinks.json",
        "destination": "assets/assetlinks.json"
      },
      {
        "source": "/public/**",
        "destination": "/public.html"
      },
      {
        "source": "**",
        "destination": "/index.html"
      }
    ],
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"]
  },
  "storage": {
    "rules": "storage.rules"
  }
}

如您所见,我的资产文件夹中有我的assetlink.json。当我导航到文件时,我得到的只是:

[ ]

当我尝试将 pwa 部署到 Playstore 时,我收到了暂停通知,因为 google 认为我不是 pwa 的所有者。

任何帮助将不胜感激。 非常感谢!

【问题讨论】:

  • 我看不出有什么不可行的原因,所以我最好的猜测是空版本是实际部署的版本。
  • 我也有同样的问题。看起来 firebase 托管重写不适用于 /.well-known/assetlinks.json 作为源
  • 同样的问题,有人解决了吗?

标签: firebase google-play progressive-web-apps firebase-hosting


【解决方案1】:

所以我也遇到了同样的问题,原来你不需要重写,只需在构建应用程序后将其放在“dist”文件夹下的 .well-knwon 下即可。 示例还包含 ios 文件

{
  "hosting": {
    "target": "main", 
    "public": "dist",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**/apple-app-site-association",
        "destination": "/.well-known/apple-app-site-association"
      },
      {
        "source": "**",
        "destination": "/index.html"
      }
    ],
    "headers": [ 
      {
        "source": "**",
        "headers": [ {
          "key": "Cache-Control",
          "value": "no-store"
        },
        {
          "key": "Expires",
          "value": "0"
        },
        {
          "key": "Pragma",
          "value": "no-cache"
        } ]
      },
      {
        "source":"**/.well-known/**",
        "headers":[{
          "key":"Content-Type",
          "value":"application/json"
        }]
      }
    ]
  }
}

ios 需要重写的原因是因为它们在执行 get 调用时不附加 .json,而且它们要求响应的标头是 content-type:application/json

【讨论】:

  • 对我不起作用。我想从 apk (twa) 中删除 url
【解决方案2】:

我也有同样的问题,张布鲁斯的回答对我来说效果很好。 为了支持这一点,对于像我这样使用 ReactFirebase 的人。

  1. .well-known文件夹包括assetlinks.json文件放在public文件夹下

  1. 不需要在 firbase.json 中编辑“重写”

  2. npm run build, firebase deploy --only 托管

最后,您可以从托管 url 以及 localhost 中看到文件的内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-21
    • 1970-01-01
    • 2020-10-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多