有没有办法将PWA / TWA应用放在子域中

时间:2019-05-23 16:40:43

标签: progressive-web-apps trusted-web-activity

我正在尝试将渐进式Web应用程序添加到我的服务器。我不想为每个应用程序创建一个新的网站。我的偏好是将每个应用程序添加到以下网站的子域中:www.example.com/app1

问题在于,当我在此处运行语句列表生成器时:https://developers.google.com/digital-asset-links/tools/generator

仅当我将assetlinks.json放在此处:www.example.com时,此方法才有效。如果是这种情况,那么我只能在www.example.com中拥有一个应用程序。我已经尝试在此处放置assetlinks.json 1)www.example.com/app1 2)www.example.com/app1/.well-known和3)www.example.com。唯一有效的方法是#3。

还向androidmanifest.xml添加了以下意图过滤器,但该过滤器不起作用:

<intent-filter android:label="@string/app_name" android:autoVerify="true" >
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE"/>
            <!-- Edit android:host to handle links to the target URL-->
            <data android:scheme="https"
                android:host="example.com"
                android:pathPrefix="/app1" />
</intent-filter>

我不敢相信每个渐进式Web应用程序都必须有一个不同的网站。有什么建议吗?

1 个答案:

答案 0 :(得分:1)

可以做到。例如,假设您正在开发2个应用程序:

而且,由于这些应用程序将是不同的TWA,所以这也意味着每个应用程序都有不同的程序包名称:

assetlinks.json文件应该在https://example.com/.well-known/assetlinks.json上可用,并且应该列出两个应用程序:

[
  {
    "relation": ["delegate_permission/common.handle_all_urls"],
    "target" : { "namespace": "android_app", "package_name": "com.example.app1",
                 "sha256_cert_fingerprints": ["<APP_1_FINGERPRINT>"] }
  }, 
  {
    "relation": ["delegate_permission/common.handle_all_urls"],
    "target" : { "namespace": "android_app", "package_name": "com.example.app2",
                 "sha256_cert_fingerprints": ["<APP_2_FINGERPRINT>"] }
  }

]

每个应用程序都有其自己的asset_statements声明,将其链接到授权来源:

[{ "relation": ["delegate_permission/common.handle_all_urls"],
   "target": {"namespace": "web", "site": "https://example.com"}}]

需要注意的几件事:

  1. 如果应用程序1将打开https://example.com/app1。但是,如果用户导航到https://example.com/app2,他们将保持全屏状态。对于应用程序2导航到/ app1,也是如此。
  2. 应用程序1有可能启动TWA打开https://example.com/app2,反之亦然。因此,如果您不信任所有PWA和相应的应用程序,则不建议使用此方法。

如果上述两个问题中的任何一个都是问题,那么使用子域将是一个更好的解决方案。