Giter VIP home page Giter VIP logo

n-meta's Introduction

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:

N-Meta: [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.

    ...
    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"),
            ]
        )
        ...

Getting started 🚀

Configure NMeta as per your needs, for example:

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

Next, add the middleware directly to your routes (e.g. in routes.swift):

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

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

app.middlewares.use(NMetaMiddleware())

🏆 Credits

This package is developed and maintained by the Vapor team at Nodes.

📄 License

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

n-meta's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

valen90

n-meta's Issues

Consider making it generic

We could consider making the header information configurable, so you basically register a key (String) and a value transformer (some protocol). The package then comes out of the box with configurations for the current setup.

Add Reminder to add new exceptPaths

Add a reminder/gotcha/heading that in case you are using meta in a project that would serve files from directories not listed in the exceptPaths array you would have to add these.

Consider dialling back on the requirements when initializing NMeta

When attempting to create a new NMeta struct as an extension on a Request this sanity check exists

guard components.count == 5 else {
    throw NMetaError.invalidHeaderFormat
}

This works fine for the native platforms but for a request from a web platform the last three parts can be extracted from the User-Agent as described in the README

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

Therefore, we need to extend the checking to consider web and then extract what can be extracted from the User-Agent if the platform is web before we throws errors

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.