hot

Pub

Screenshot of terminal

Supports hot reloading of Angel servers on file changes. This is faster andmore reliable than merely reactively restarting a Process.

This package only works with the Angel framework.

Installation

In your pubspec.yaml:

1. dependencies:
2. angel_framework: ^2.0.0-alpha
3. angel_hot: ^2.0.0

Usage

This package is dependent on the Dart VM service, so you must runDart 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 pathsto 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 instancewithin a separate function, conventionally named createServer.

Using this in production mode is not recommended, unless you arespecifically intending for a "hot code push" in production..

You can watch:

  • Files
  • Directories
  • Globs
  • URI's
  • package: URI's
1. import 'dart:async';
2. import 'dart:convert';
3. import 'dart:io';
4. import 'package:angel_framework/angel_framework.dart';
5. import 'package:angel_hot/angel_hot.dart';
6. import 'package:logging/logging.dart';
7. import 'src/foo.dart';

9. main() async {
10. var hot = new HotReloader(createServer, [
11. new Directory('src'),
12. new Directory('src'),
13. 'main.dart',
14. Uri.parse('package:angel_hot/angel_hot.dart')
15. ]);
16. await hot.startServer('127.0.0.1', 3000);
17. }

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

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

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

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

33. app.logger = new Logger('angel')
34. ..onRecord.listen((rec) {
35. print(rec);
36. if (rec.error != null) {
37. print(rec.error);
38. print(rec.stackTrace);
39. }
40. });

42. return app;
43. }