Rate Limiter and SSL enforcing middleware.
Update your Package.swift
file.
.Package(url: "https://github.com/nodes-vapor/gatekeeper", majorVersion: 0)
Both the rate limiter and SSL-enforcing middleware are easy to configure and get running.
SSLEnforcer
has three configurable fields: the error to be thrown, your Droplet
and the environments you wish to enforce on. The environments defaults to [.production]
.
let drop = Droplet()
// this will only enforce if running in `production` mode.
let enforcer = SSLEnforcer(error: Abort.notFound, drop: drop)
If you wish to secure your endpoints during development you can do the following:
let enforcer = SSLEnforcer(
error: Abort.notFound,
drop: drop,
environments: [
.production,
.development
]
)
RateLimiter
has two configurable fields: the maximum rate and the cache to use. If you don't supply your own cache the limiter will create its own, in-memory cache.
let limiter = RateLimiter(rate: Rate(10, per: .minute))
The currently implemented intervals are:
case .second
case .minute
case .hour
case .day
This package is developed and maintained by the Vapor team at Nodes.
This package is open-sourced software licensed under the MIT license