Let's Encrypt support for the shelf package (free and automatic HTTPS certificate support).

Overview

shelf_letsencrypt

pub package Null Safety Codecov CI GitHub Tag New Commits Last Commits Pull Requests Code size License

shelf_letsencrypt brings support for Let's Encrypt to the shelf package.

Usage

To use the LetsEncrypt class

import 'dart:io';

import 'package:shelf/shelf.dart';
import 'package:shelf_letsencrypt/shelf_letsencrypt.dart';

void main(List<String> args) async {
  var domain = args[0]; // Domain for the HTTPS certificate.
  var domainEmail = args[1];
  var certificatesDirectory = args.length > 2 ? args[2] : null; // Optional argument.

  certificatesDirectory ??= '/etc/letsencrypt/live'; // Default directory.

  // The Certificate handler, storing at `certificatesDirectory`.
  final certificatesHandler = CertificatesHandlerIO(Directory(certificatesDirectory));

  // The Let's Encrypt integration tool in `staging` mode:
  final LetsEncrypt letsEncrypt = LetsEncrypt(certificatesHandler, production: false);

  // `shelf` Pipeline:
  var pipeline = const Pipeline().addMiddleware(logRequests());
  var handler = pipeline.addHandler(_processRequest);

  var servers = await letsEncrypt.startSecureServer(
    handler,
    domain,
    domainEmail,
    port: 80,
    securePort: 8443,
  );

  var server = servers[0]; // HTTP Server.
  var serverSecure = servers[1]; // HTTPS Server.

  // Enable gzip:
  server.autoCompress = true;
  serverSecure.autoCompress = true;

  print('Serving at http://${server.address.host}:${server.port}');
  print('Serving at https://${serverSecure.address.host}:${serverSecure.port}');
}

Response _processRequest(Request request) {
  return Response.ok('Requested: ${request.requestedUri}');
}

Source

The official source code is hosted @ GitHub:

Features and bugs

Please file feature requests and bugs at the issue tracker.

Contribution

Any help from the open-source community is always welcome and needed:

  • Found an issue?
    • Please fill a bug report with details.
  • Wish a feature?
    • Open a feature request with use cases.
  • Are you using and liking the project?
    • Promote the project: create an article, do a post or make a donation.
  • Are you a developer?
    • Fix a bug and send a pull request.
    • Implement a new feature.
    • Improve the Unit Tests.
  • Have you already helped in any way?
    • Many thanks from me, the contributors and everybody that uses this project!

If you donate 1 hour of your time, you can contribute a lot, because others will do the same, just be part and start with your 1 hour.

TODO

  • Add support for multiple HTTPS domains and certificates.
  • Add helper to generate self-signed certificates (for local tests).

Author

Graciliano M. Passos: gmpassos@GitHub.

License

Apache License - Version 2.0

You might also like...

Easy to use session wrapper that adds support to session storage and management in flutter.

flutter_session_manager Adds an easy to use wrapper to session management in flutter. Allows for easy session storage and management. The session pers

Feb 15, 2022

A Dart package which supports checking if a current package is up-to-date.

pub_updater A Dart package which enables checking whether packages are up to date and supports updating them. Intended for use in CLIs for prompting u

Oct 27, 2022

A generator to create config class from json files that support many environments

A generator to create config class from json files that support many environments. Motivation If you use a json file to config your applications, perp

Oct 9, 2021

Queen support for localization in flutter

Queen support for localization in flutter

Nations 🌍 Features translation without context 🚀 custom configuration value not found builder fallback locale supported locales fall back to base be

Jun 22, 2022

library to help you create database on local memory, support json local database inspired by lowdb

Licensed Licensed under the MIT License http://opensource.org/licenses/MIT. SPDX-License-Identifier: MIT Copyright (c) 2021 Azkadev http://github.c

Oct 17, 2022

Flutter Map plugin for ArcGIS Esri. Currently support feature layer (point, polygon)

Flutter Map plugin for ArcGIS Esri Currently support feature layer(point, polygon, polyline coming soon) We are working on more features A Dart implem

Nov 9, 2022

A flutter package provides controllers and editors for complex models and lists

A flutter package provides controllers and editors for complex models and lists

This package provides controllers and editors for complex models and lists and is inspired by simplicity of TextEditingController. It encapsulates sta

Sep 1, 2022

A dart package to help you parse and evaluate infix mathematical expressions into their prefix and postfix notations.

A dart package to help you parse and evaluate infix mathematical expressions into their prefix and postfix notations.

Jan 28, 2022
Comments
  • Self HTTP test not OK!

    Self HTTP test not OK!

    I am getting this error: "Self HTTP test not OK!"

    while calling

    await letsEncrypt.startSecureServer()
    

    having this simple server:

    import 'dart:io';
    import 'dart:async' show runZonedGuarded;
    import 'package:path/path.dart' show join, dirname;
    
    import 'package:shelf/shelf.dart';
    import 'package:shelf/shelf_io.dart';
    import 'package:shelf_router/shelf_router.dart';
    import 'package:shelf_gzip/shelf_gzip.dart';
    import 'package:shelf_static/shelf_static.dart';
    import 'package:shelf_letsencrypt/shelf_letsencrypt.dart';
    
    Response _echoHandler(Request request) {
      final message = request.params['message'];
      return Response.ok('$message\n');
    }
    
    void main(List<String> args) async {
      final ip = InternetAddress.anyIPv4;
    
      final pathToBuild = join(dirname(Platform.script.toFilePath()), '../../../',
          'mtg.studio.project/ui/build/web');
      final staticHandler =
          createStaticHandler(pathToBuild, defaultDocument: 'index.html');
    
      // Configure routes.
      final app = Router();
      app.get('/sample/route/<message>', _echoHandler);    
    
      runZonedGuarded(() async {
        final handlers = Pipeline()
            .addMiddleware(logRequests())
            .addMiddleware(gzipMiddleware)
            .addHandler(Cascade().add(staticHandler).add(app).handler);
    
        // For running in containers, we respect the PORT environment variable.
        final port = int.parse(Platform.environment['PORT'] ?? '3030');
        final domain = 'domain.com';
        final domainEmail = '[email protected]';
        final certificatesDirectory = '.'; // /etc/letsencrypt/live';
    
        // The Certificate handler, storing at `certificatesDirectory`.
        final certificatesHandler =
            CertificatesHandlerIO(Directory(certificatesDirectory));
    
        // The Let's Encrypt integration tool in `staging` mode:
        final LetsEncrypt letsEncrypt =
            LetsEncrypt(certificatesHandler, production: false);
    
        // final server = await serve(handlers, ip, port);
        final servers = await letsEncrypt.startSecureServer(
          handlers,
          domain,
          domainEmail,
          port: port,
          securePort: 3443,
        );
    
        var server = servers[0]; // HTTP Server.
        var serverSecure = servers[1]; // HTTPS Server.
    
        // Enable gzip:
        server.autoCompress = true;
        serverSecure.autoCompress = true;
        print('☀️Serving at http://${server.address.host}:${server.port}');
        print(
            '☀️Serving at https://${serverSecure.address.host}:${serverSecure.port}');
      }, (e, stackTrace) => print('🐞Server error: $e $stackTrace'));
    }
    
    opened by gaddlord 0
  • Is it possible to listen on multiple domains?

    Is it possible to listen on multiple domains?

    I'd like to have a server that listens on port 443 for multiple domains, resolves the certificates separately, and routes the requests in a per-domain basis. Is this supported / planned? Any thoughts on how I contribute to this package (what design decisions would you prefer)?

    enhancement dependent 
    opened by isoos 4
Releases(1.0.0)
Owner
Graciliano Monteiro Passos
Graciliano Monteiro Passos
An Android app to encrypt plain text notes

AndSafe AndSafe is an Android app that encrypts plain text notes. With version 3, AndSafe3 is re-implemented with Flutter and is now open source. FAQ

Clarence K.C. Ho 4 Jul 9, 2022
A package that lets you include a cool, nice looking and validated Password TextFormField in your app to enhance user experience. The package is fully & easily modifiable.

A package that lets you include a cool, nice looking and validated Password TextFormField in your app to enhance user experience. The package is fully

Muhammad Hamza 20 Jun 7, 2022
Dart wrapper via dart:ffi for https://github.com/libusb/libusb

libusb Dart wrapper via dart:ffi for https://github.com/libusb/libusb Environment Windows(10) macOS Linux(Ubuntu 18.04 LTS) Usage Checkout example Fea

Woodemi Co., Ltd 28 Dec 20, 2022
Flutter App which lets you share memes among your friends.

meme_share_app About App Flutter App which lets you share memes among your friends . Here one have 2 options : NEXT : Load Next Meme. SHARE : To Share

null 0 Oct 30, 2021
Library for help you make userbot or bot telegram and support tdlib telegram database and only support nodejs dart and google-apps-script

To-Do telegram client dart ✅️ support multi token ( bot / userbot ) ✅️ support bot and userbot ✅️ support telegram-bot-api local server ✅️ support tel

Azka Full Snack Developer:) 73 Jan 7, 2023
Boilerplate-free form validation library

Valform Boilerplate-free form validation library. Preface Why? Why not Formz? Why Valform? Getting started Simple Usage Inspiration Why? There is no c

Alexander Farkas 3 Nov 14, 2021
Boilerplate-free form validation library

Trigger Boilerplate-free form validation library. Preface Why? Why not Formz? Why Trigger? Getting started Simple Usage Inspiration Why? There is no c

Alexander Farkas 3 Nov 14, 2021
The Dart Time Machine is a date and time library for Flutter, Web, and Server with support for timezones, calendars, cultures, formatting and parsing.

The Dart Time Machine is a date and time library for Flutter, Web, and Server with support for timezones, calendars, cultures, formatting and parsing.

null 2 Oct 8, 2021
null 2 Apr 17, 2022
Okan YILDIRIM 37 Jul 10, 2022