Search code examples
firebasegoogle-playprogressive-web-appsfirebase-hosting

firebase hosting not displaying the correct file contents


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!


Solution

  • 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