2

For the auto-fill password to work on the Apple platforms, I am testing out Apple App Site Association (AASA) Validator in this website. I have added the required json in the Public/.well-known/apple-app-site-association file for the auto-fill password to work on my iOS application.

The result from this test comes back with this error: Your file's 'content-type' header was not found or was not recognized.

Does anyone have ever encounter this issue? It seems that the AASA file is not being downloading into my device.

Note that on iOS 14, AASA files will be delivered via Apple's CDN, which is different from how AASA files are currently downloaded.

Is there something else to do about it on my Vapor 4 project to make things work? enter image description here

Roland Lariotte
  • 2,606
  • 1
  • 16
  • 40
  • Do you have nginx in front of your vapor application? – imike Mar 04 '21 at 11:54
  • 3
    If yes then you could declare right content-type in your virtual host file `location /.well-known/apple-app-site-association { default_type application/json; }` if not then you should create middleware in vapor which will stream `apple-app-site-association` with the right `content-type` header – imike Mar 04 '21 at 11:57
  • I am not using nginx. My Vapor app is deployed on Heroku. Can you show me how to create this specific Middleware? – Roland Lariotte Mar 04 '21 at 14:08
  • 2
    Just take a look at `FileMiddleware` sources and edit it. Also on heroku seems you're using `FileMiddleware` which is bad for production cause EACH request (even to API endpoints) it check for a file on disk first and only then pass request to the next responder(router) which is very very slow for production. If you will do your own middleware just take care about that aspect, check headers or url.lastPathComponent to know that you have to look for file on disk and if not then pass to next responder immediately. – imike Mar 04 '21 at 16:24
  • I setup the FileMiddleware for the Vapor app to read the `Public` folder where the `apple-app-site-association` file is. It is read correctly on localhost but not when deployed on Heroku. It seems that Heroku do not read this `Public` folder. Is there a way to tell Heroku to do so? – Roland Lariotte Mar 04 '21 at 17:41
  • 4
    `Public` folder works well on Heroku, the only problem that `apple-app-site-association` has no `.json` extension, that's why FileMiddleware or even nginx can't provide the right `content-type` header, so you have to do it yourself in a custom middleware. – imike Mar 04 '21 at 18:49

1 Answers1

1

I meat the same issue, follow by imike's answer and doing some research, here is the solution.

  1. create a custom Middleware
struct UniversalLinksMiddleware: Middleware {
    
    func respond(to request: Request, chainingTo next: Responder) -> EventLoopFuture<Response> {
        guard request.url.string == "/.well-known/apple-app-site-association" else {
            return next.respond(to: request)
        }
        
        return next.respond(to: request).map { response in
            response.headers.add(name: "content-type", value: "application/json")
            return response
        }
    }
    
}

  1. add this middleware at config.swift file. Be aware of the order you add middleware, you must add it before FileMIddleware. Because the responses leaving your application goes through the middleware in reverse order.
app.middleware.use(UniversalLinksMiddleware())
app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
蘇健豪
  • 541
  • 4
  • 13