Skip to content

jxstxn1/shelf_enforces_ssl

Repository files navigation

Shelf Enforces SSL

Ensures that only API Requests with a HTTPS connection are accepted. Inspired by https://github.com/hengkiardo/express-enforces-ssl

Installing

dart pub add shelf_enforces_ssl

Usage

As shelf middleware

import 'package:shelf_enforces_ssl/shelf_enforces_ssl.dart';

  var handler =
      const Pipeline().addMiddleware(enforceSSL()).addMiddleware(logRequests()).addHandler(_echoRequest);

As dart_frog middleware

import 'package:shelf_enforces_ssl/shelf_enforces_ssl.dart';

Handler enforceSSL(Handler handler) {
    return handler.use(fromShelfMiddleware(enforceSSL()));
}

Defining custom error response

.addMiddleware(
    enforceSSL(
      errorResponse: Response(
        403,
        body: 'Please use HTTPS when you try to send data to this API',
      ),
    ),
  ),

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages