N-MetaⓂ️

Swift Version Vapor Version Circle CI codebeat badge codecov Readme Score GitHub license

此软件包强制客户端在所有请求中发送特定的标头。

N-Meta: [PLATFORM];[ENVIRONMENT];[APP_VERSION];[DEVICE_OS];[DEVICE]

如果你正在运行旧版本的 Vapor,请点击这里查看。

此标头可能如下所示 android;production;1.2.3;4.4;Samsung S7

对于 Web 平台,仅需要平台和环境,因为其余信息可以在 User-Agent 中找到。

为什么不直接使用 User-Agent

📦 安装

更新你的 Package.swift 文件。

    ...
    dependencies: [
        ...
        .package(url: "https://github.com/nodes-vapor/n-meta.git", from: "4.0.0")
    ],
    targets: [
        .target(
            name: "App",
            dependencies: [
                ...
                .product(name: "NMeta", package: "n-meta"),
            ]
        )
        ...

🚀 快速开始

根据你的需求配置 NMeta,例如

app.nMeta = .init(exceptPath: ["/admin"])

接下来,将中间件直接添加到你的路由中(例如,在 routes.swift 中)

app.grouped(NMetaMiddleware()).get("hello") { req in
    "Hello, world!"
}

或者全局添加中间件(例如,在 configure.swift 中),这将把它添加到所有路由

app.middlewares.use(NMetaMiddleware())

🏆 鸣谢

此软件包由 Nodes 的 Vapor 团队开发和维护。

📄 许可证

此软件包是根据 MIT 许可证 开源的软件。