firebase 托管不显示正确的文件内容
firebase hosting not displaying the correct file contents
我正在尝试在 firebase 上为 PWA 托管一个 assetlinks.json 文件,问题是我无法查看文件的内容。我认为这与我的 firebase.json 文件有关。 link 我想得到的是
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 的所有者。
非常感谢任何帮助。
非常感谢!
所以我运行也遇到了同样的问题,原来你不需要重写,只需将它放在"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 需要 re-write 的原因是因为他们在执行 get 调用时不附加 .json,他们还要求响应的 header 是 content-type:application/json
我也遇到了同样的问题,张布鲁斯的回答对我来说很管用。
为了支持这一点,对于像我这样使用 React 和 Firebase 的人。
- 将.well-known文件夹包括assetlinks.json文件放在public文件夹
下
不需要在 firbase.json
中编辑 'rewrite'
npm 运行 build, firebase deploy --only hosting
最后,您可以从您的主机 url 以及本地主机上看到文件的内容。
我正在尝试在 firebase 上为 PWA 托管一个 assetlinks.json 文件,问题是我无法查看文件的内容。我认为这与我的 firebase.json 文件有关。 link 我想得到的是 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 的所有者。
非常感谢任何帮助。 非常感谢!
所以我运行也遇到了同样的问题,原来你不需要重写,只需将它放在"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 需要 re-write 的原因是因为他们在执行 get 调用时不附加 .json,他们还要求响应的 header 是 content-type:application/json
我也遇到了同样的问题,张布鲁斯的回答对我来说很管用。 为了支持这一点,对于像我这样使用 React 和 Firebase 的人。
- 将.well-known文件夹包括assetlinks.json文件放在public文件夹 下
不需要在 firbase.json
中编辑 'rewrite'npm 运行 build, firebase deploy --only hosting
最后,您可以从您的主机 url 以及本地主机上看到文件的内容。