Deep linking to native app

What is the name of the domain?

erfgoed.app

What is the issue you’re encountering

Can I host a json file in the root domain when the website is not hosted on Cloudflare?

What steps have you taken to resolve the issue?

We need this json file for deep linking to our native app.

You can host and serve it from the origin server, why not? :thinking:
No need to go for a solution with Cloudflare then.

Furthermore, if your domain is using Cloudflare, simply you could return a JSON using a Worker on an route (path) e.g. example.com/.well-known/assetlinks.json.

Example:

To make it work, make sure your DNS records for your hostname such as example.com and/or www are proxied and set to :orange: under the DNS tab of Cloudflare dashboard for your zone.

Make sure to bound your Worker to the example.com/.well-known/assetlinks.json.

Example worker code for deep linking (modify it for your needs, or if you already have one:

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
  // Define your JSON manifest data for deep-linking here
  const deepLinkManifest = {
    "name": "My App",
    "short_name": "MyApp",
    "start_url": "/home",
    "display": "standalone",
    "background_color": "#ffffff",
    "theme_color": "#000000",
    "description": "An app for deep-linking purposes",
    "icons": [
      {
        "src": "/images/icon-192x192.png",
        "sizes": "192x192",
        "type": "image/png"
      },
      {
        "src": "/images/icon-512x512.png",
        "sizes": "512x512",
        "type": "image/png"
      }
    ],
    "deep_links": [
      {
        "rel": "alternate",
        "href": "myapp://home",
        "type": "application/json"
      },
      {
        "rel": "alternate",
        "href": "myapp://profile/{userId}",
        "type": "application/json"
      }
    ]
  };

  // Return the deep-linking JSON manifest as a response
  return new Response(JSON.stringify(deepLinkManifest), {
    headers: {
      'Content-Type': 'application/json',
      'Cache-Control': 'public, max-age=3600' // cache json for 1 hour
    }
  })
}