How to read the apple-app-site-association file on Vapor 4?

702 views Asked by At

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

1

There are 1 answers

0
蘇健豪 On BEST ANSWER

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))