简体   繁体   中英

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

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? 在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM