platform/packages/hot
2023-05-27 07:42:46 +08:00
..
example Publish hot 2021-05-15 21:17:18 +08:00
lib Fixed issue 83 2022-10-06 08:00:03 +08:00
screenshots Updated hot reloader 2021-07-18 15:18:31 +08:00
.gitignore Publish angel3_configuration 2021-05-14 19:27:54 +08:00
analysis_options.yaml Updated hot 2021-09-11 11:18:35 +08:00
AUTHORS.md Publish angel3_configuration 2021-05-14 19:27:54 +08:00
CHANGELOG.md Updated production and hot to Dart 3 2023-05-27 07:42:46 +08:00
LICENSE Updated hot 2021-09-11 11:18:35 +08:00
melos_angel3_hot.iml Added melos 2022-03-19 09:37:28 +08:00
pubspec.yaml Updated production and hot to Dart 3 2023-05-27 07:42:46 +08:00
README.md Updated production and hot to Dart 3 2023-05-27 07:42:46 +08:00

Angel3 Hot Reloader

Pub Version (including pre-releases) Null Safety Gitter License

Screenshot of terminal

Supports hot reloading of Angel3 servers on file changes. This is faster and more reliable than merely reactively restarting a Process. This package only works with the Angel3 framework.

Not recommended to use in production, unless you are specifically intending for a "hot code push" in production..

Installation

In your pubspec.yaml:

dependencies:
  angel3_framework: ^8.0.0
  angel3_hot: ^8.0.0

Usage

This package is dependent on the Dart VM service, so you must run Dart with the --observe (or --enable-vm-service) argument!!!

Usage is fairly simple. Pass a function that creates an Angel server, along with a collection of paths to watch, to the HotReloader constructor. The rest is history!!!

The recommended pattern is to only use hot-reloading in your application entry point. Create your Angel instance within a separate function, conventionally named createServer.

You can watch:

  • Files
  • Directories
  • Globs
  • URI's
  • package: URI's
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_hot/angel3_hot.dart';
import 'package:logging/logging.dart';
import 'src/foo.dart';

main() async {
  var hot = HotReloader(createServer, [
    Directory('src'),
    'main.dart',
    Uri.parse('package:angel3_hot/angel3_hot.dart')
  ]);
  await hot.startServer('127.0.0.1', 3000);
}

Future<Angel> createServer() async {
  var app = Angel()..serializer = json.encode;

  // Edit this line, and then refresh the page in your browser!
  app.get('/', (req, res) => {'hello': 'hot world!'});
  app.get('/foo', (req, res) => Foo(bar: 'baz'));

  app.fallback((req, res) => throw AngelHttpException.notFound());

  app.encoders.addAll({
    'gzip': gzip.encoder,
    'deflate': zlib.encoder,
  });

  app.logger = Logger('angel')
    ..onRecord.listen((rec) {
      print(rec);
      if (rec.error != null) {
        print(rec.error);
        print(rec.stackTrace);
      }
    });

  return app;
}