Continuing the discussion from TWA application requires assetlinks.json:
What I’m trying to do:
I am trying to publish an app through Google Play Store and one of the things required to remove the URL bar is to serve an asset links JSON file.
The usual approach is to host this at https://example.com/.well-known/assetlinks.json and then the API take scare of the rest. The problem is that Anvil takes this as a server call and therefor never serves the data.
What I’ve tried and what’s not working:
Taking a very different approach I found that the Anvil logs we catching this error:
anvil.server.NoServerFunctionError: No server function matching "http-wellknown:/assetlinks.json" has been registered
So I figured maybe I could create a callable server function to return the data.
So when you navigate to example.com/.well-known/assetlinks.json it should show you the contents of that JSON file.
Which works without error but doesn’t display the data on the page so presumably cant be processed by the API.
Code Sample:
@anvil.server.callable("http-wellknown:/assetlinks.json")
def serve_well_known (*args, **kwargs):
asset_links_json = [
{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "com.example.twa",
"sha256_cert_fingerprints":
["..."]
}
}
]
url_media = anvil.URLMedia("https://example.com/_/theme/assetlinks.json")
return url_media
The question is how do I go from a server return function into HTML or something that can be read by the request for example.com/.well-known/assetlinks.json
I have tried a number of return types including json.dumps()
and creating a HttpResponse
Object (whcih cannot be serialised in the return) but no joy.
Clone link:
share a copy of your app