firebase 托管未显示正确的文件内容 [英] firebase hosting not displaying the correct file contents

查看:66
本文介绍了firebase 托管未显示正确的文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

<预><代码> [{关系":[delegate_permission/common.handle_all_urls"],目标": {"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.json"},火库":{"rules": "firestore.rules",索引":firestore.indexes.json"},职能": {预部署":["npm --prefix \"$RESOURCE_DIR\" 运行 lint","npm --prefix \"$RESOURCE_DIR\" 运行构建"]},主持":{"公开": "公开",重写":[{"source": "/.well-known/assetlinks.json",目的地":资产/资产链接.json"},{"source": "/public/**",目的地":/public.html"},{来源": "**",目的地":/index.html"}],忽略":[firebase.json",**/.*",**/node_modules/**"]},贮存": {规则":存储.规则"}}

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

<代码>[ ]

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

非常感谢任何帮助.非常感谢!

解决方案

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

{主持":{目标":主要","public": "dist",忽略": ["firebase.json","**/.*",**/node_modules/**"],重写":[{"source": "**/apple-app-site-association",目的地":/.well-known/apple-app-site-association"},{来源": "**",目的地":/index.html"}],标题":[{来源": "**",标题":[{"key": "缓存控制",价值":无商店"},{"key": "过期",值":0"},{"key": "Pragma",值":无缓存"}]},{"source":"**/.well-known/**",标题":[{"key":"内容类型",值":应用程序/json"}]}]}}

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

I am trying to host a assetlinks.json file for a PWA on firebase, The issue is that I am unable to view the content of the file. I think it has something to do with my firebase.json file. The link I am trying to get is https://bionomichealth.com/.well-known/assetlinks.json and it contains:

    [
  {
    "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"]
    }
  }
]

and finally, here is my 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"
  }
}

as you can see, I have my assetlink.json in my assets folder. When I navigate to the file, All i get is:

[ ]

and When I attempted to deploy the pwa to the Playstore I got a suspended notice as google thinks that I am not the owner of the pwa.

Any help would be very much appreciated. Thank you very much!

解决方案

So I ran into the same issue as well, it turns out you don't need to rewrite, just put it under .well-knwon under the "dist" folder after your app is built. example also contain ios file

{
  "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"
        }]
      }
    ]
  }
}

the reason ios needs re-write is because they dont append .json while doing the get call, also they require the header of the response to be content-type:application/json

这篇关于firebase 托管未显示正确的文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆