如何阅读 Vapor 4 上的 apple-app-site-association 文件?

问题描述

为了在 Apple 平台上使用自动填充密码,我正在此 website 中测试 Apple App Site Association (AASA) Validator。 我已在 Public/.well-kNown/apple-app-site-association 文件添加了所需的 json,以便在我的 iOS 应用程序上使用自动填充密码。

此测试的结果返回此错误Your file's 'content-type' header was not found or was not recognized

有人遇到过这个问题吗?似乎 AASA 文件没有下载到我的设备中。

请注意,在 iOS 14 上,AASA 文件将通过 Apple 的 CDN 传送,这与当前下载 AASA 文件的方式不同。

在我的 Vapor 4 项目中还有什么可以做的吗?

enter image description here

解决方法

我遇到了同样的问题,按照 imike 的回答并做了一些研究,这是解决方案。

  1. 创建自定义中间件
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. config.swift 文件中添加此中间件。请注意添加中间件的顺序,必须在 FileMIddleware 之前添加。因为离开应用程序的响应以相反的顺序通过中间件。
app.middleware.use(UniversalLinksMiddleware())
app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...