vercel / serve-handler

The foundation of `serve`

Home Page:https://npmjs.com/serve-handler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to serve file without extension .well-known/apple-app-site-association

kachar opened this issue · comments

Using serve to deliver a static pre-built create-react-app.

serve -s /web/build --listen 5000 --no-clipboard

The file .well-known/apple-app-site-association is part of the served directory but user receives the contents of index.html instead of the static file.

$ curl -v frontend:5000/.well-known/apple-app-site-association
*   Trying 172.26.0.6...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x55d399370f50)
* Connected to frontend (172.26.0.6) port 5000 (#0)
> GET /.well-known/apple-app-site-association HTTP/1.1
> Host: frontend:5000
> User-Agent: curl/7.64.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Length: 3668
< Content-Disposition: inline; filename="index.html"
< Accept-Ranges: bytes
< ETag: "5f5cc5f26a26ca0e5c724317646b36fa5c9f84f5"
< Content-Type: text/html; charset=utf-8
< Vary: Accept-Encoding
< Date: Tue, 16 Feb 2021 09:51:45 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
< 
<!doctype html>...

A file just next to it .well-known/assetlinks.json is being resolved correctly.

$ curl -v frontend:5000/.well-known/assetlinks.json
*   Trying 172.26.0.6...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x557f10cd4f50)
* Connected to frontend (172.26.0.6) port 5000 (#0)
> GET /.well-known/assetlinks.json HTTP/1.1
> Host: frontend:5000
> User-Agent: curl/7.64.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Length: 647
< Content-Disposition: inline; filename="assetlinks.json"
< Accept-Ranges: bytes
< ETag: "dd82311f2234ea4637b771ce3f7a4be2a5253fd5"
< Content-Type: application/json; charset=utf-8
< Vary: Accept-Encoding
< Date: Tue, 16 Feb 2021 09:55:17 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
< 
[
  {
    "relation"....

I've tried defining a serve.json config with excluded directory in cleanUrls but did not solve it.

{
    "cleanUrls": [
      "/**",
      "/!.well-known/**"
    ]
}

Universal Links documentation: https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/UniversalLinks.html

Any help would be appreciated!

commented

Having the same issue, anyone have a fix for this?

shameless self-promotion alert:
this feature is fixed in my @warren-bank/serve fork of serve

The fix for this is to create the apple-app-site-association as apple-app-site-association.json and then create a rewrite rule inside of a file in your public directory called serve.json. The contents of that file should look like this.

{
  "rewrites": [
    {
      "source": "!.well-known/**",
      "destination": "index.html"
    },
    {
      "source": ".well-known/apple-app-site-association",
      "destination": ".well-known/apple-app-site-association.json"
    }
  ]
}

Then when you start your static file server, you don't use the -s or --single argument. You start it using the following command.

serve -c serve.json

The first item will send all requests that don't exist inside of .well-known to index.html, and the second rewrite will send requests for that specific URL to the apple-app-site-association.json file and assign a content-type: application/json header to it. All other files with file extensions should be served as normal, ignoring any rewrite rules.

I am having this same issue

I am also having the same issue :(