Swift
Clone or download
steffendsommer Merge pull request #17 from nodes-vapor/bugfix/allow-global-middle-re…
…gistration

Add the middleware as a service for global reg.
Latest commit 48cfe4e May 14, 2018
Permalink
Failed to load latest commit information.
.circleci
Sources/NMeta Add the middleware as a service for global reg. May 14, 2018
Tests
.codebeatignore
.codecov.yml
.gitignore Syntax alignment - make Swiftlint build May 14, 2018
.swiftlint.yml
LICENSE
Package.swift
README.md Add the middleware as a service for global reg. May 14, 2018

README.md

N-Meta Ⓜ️

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

This package enforces clients to send a specific header in all requests:

NMeta: [PLATFORM];[ENVIRONMENT];[APP_VERSION];[DEVICE_OS];[DEVICE]

If you're running an older version of Vapor then have a look here:

This header can look like this android;production;1.2.3;4.4;Samsung S7

  • platform
  • environment
  • app version
  • device os
  • device

For web platform only platform and environment is required, since the rest can be found in User-Agent.

Why not just use User-Agent?

  • User-Agent is missing some of these details
  • User-Agent can be hard to extend/override
  • Default User-Agent in iOS & Android can be their client (OkHttp, Alamofire etc).

📦 Installation

Update your Package.swift file.

.package(url: "https://github.com/nodes-vapor/n-meta.git", from: "3.0.0-beta")

Getting started 🚀

Register the provider in configure.swift:

import NMeta
try services.register(NMetaProvider())

You can supply your own NMetaConfig to the provider if needed.

Next, add the middleware directly to your routes:

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

or add the middleware globally (e.g. in configure.swift) which will add it to all routes:

middlewares.use(NMetaMiddleware.self)

🏆 Credits

This package is developed and maintained by the Vapor team at Nodes. The package owner for this project is Steffen.

📄 License

This package is open-sourced software licensed under the MIT license