The Protevus Platform: Unified Full-Stack Development https://protevus.com
Find a file
2017-06-13 23:35:04 -04:00
.idea Disable if need be 2017-06-13 23:35:04 -04:00
example/basic 1.0.0 2017-06-12 15:26:45 -04:00
lib Disable if need be 2017-06-13 23:35:04 -04:00
.analysis-options First RC. 2017-06-06 08:07:59 -04:00
.gitignore First RC. 2017-06-06 08:07:59 -04:00
LICENSE Initial commit 2017-06-06 05:19:32 -04:00
pubspec.yaml Disable if need be 2017-06-13 23:35:04 -04:00
README.md 1.0.0 2017-06-12 15:26:45 -04:00

hot

Pub

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

This package only works with the Angel framework.

Installation

In your pubspec.yaml:

dependencies:
  angel_framework: ^1.0.0
  angel_hot: ^1.0.0

Usage

This package is dependent on the Dart VM service, so you must run Dart with the --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. Using this in production mode is pointless.

You can watch:

  • Files
  • Directories
  • Globs
  • URI's
  • package: URI's
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:angel_compress/angel_compress.dart';
import 'package:angel_diagnostics/angel_diagnostics.dart';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_hot/angel_hot.dart';
import 'src/foo.dart';

main() async {
  var hot = new HotReloader(createServer, [
    new Directory('config'),
    new Directory('lib'),
    new Directory('web'),
    new Directory('src'),
    'bin/server.dart',
    Uri.parse('some_file.dart'),
    Uri.parse('package:angel_hot/angel_hot.dart')
  ]);
  
  var server = await hot.startServer(InternetAddress.LOOPBACK_IP_V4, 3000);
  print(
      'Hot server listening at http://${server.address.address}:${server.port}');
}

Future<Angel> createServer() async {
  var app = new Angel();

  app.lazyParseBodies = true;
  app.injectSerializer(JSON.encode);

  app.get('/', {'hello': 'hot world!'});
  
  app.post('/foo/bar', (req, res) async {
    var result = await someLengthyOperation();
    return {'status': result};
  });

  app.after.add(() => throw new AngelHttpException.notFound());

  app.responseFinalizers.add(gzip());
  await app.configure(logRequests());
  return app;
}